Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to apply order by Window function in DAX

In PowerBI, I want to create a calculated table from table t. Using DAX, how can I write the equivalent of the following SQL query. Basically, here I am finding running sum (cumsum) using cnt ordered by date.

select
    date,
    cnt,
    sum(cnt) over (order by date) as cumsum
from
    t

This is an example output. The source table has columns d and cnt. This query adds the table cumsum.

date, cnt, cumsum
2022-01-01, 13, 13,
2022-01-02, 14, 27
2022-01-03, 18, 45
...

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Here you go.

Table1 :

enter image description here

Table2:

enter image description here

Table2 = 
ADDCOLUMNS(
    SUMMARIZE(Table1, Table1[date], Table1[cnt]),
    "cumsum", 
    VAR x= Table1[date]
    RETURN
    CALCULATE(SUM(Table1[cnt]), REMOVEFILTERS(), Table1[date] <= x )
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading