Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Can someone explain this DADX measure?

I am new to dax, and am having trouble trouble understanding this measure. Can someone who is familiar with dax break this down line by line and explain the code and functions? I feel it would be a great learning exercise for myself and perhaps others.

 

Actual =
VAR ACT = CALCULATE(SUM('COVID-19'[Cumulated]), LASTDATE('COVID-19'[Date]))
VAR PD = CALCULATE(CALCULATE(SUM('COVID-19'[Cumulated]), LASTDATE('COVID-19'[Date])),PREVIOUSDAY(LASTDATE('COVID-19'[Date])))

RETURN
IF (HASONEVALUE(TimeRange[Time Range]),
      SWITCH(VALUES(TimeRange[Time Range]),
              "Cumulated", ACT,
               "Daily", ACT - PD,
                BLANK()
      ),
      ACT
)
1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

Well that is some interesting code.

ACT - Calculates the sum of the Cumulated column in table COVID-19 within the context of the last date (latest date) within the Date column in the same COVID-19 table. So, looks like it is getting the last value from what is probably an accumulating total column.

PD - So, they wrap the same calculation as above in another CALCULATE and tag in a filter context of PREVIOUSDAY from the last date so this is basically getting the next to the last day.

In the RETURN statement, they check to see if a single value has been selected in the Time Range column in the TimeRange table. Probably a slicer. Maybe a disconnected table? If there is only one value, then it returns ACT variable.

If that is not the case, it gets the distinct values that have been selected and here I am fairly sure it just returns BLANK or an error all the time as it is unclear to that you can compare a table to a string. I have tested this and you cannot.


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Community Champion
Community Champion

Well that is some interesting code.

ACT - Calculates the sum of the Cumulated column in table COVID-19 within the context of the last date (latest date) within the Date column in the same COVID-19 table. So, looks like it is getting the last value from what is probably an accumulating total column.

PD - So, they wrap the same calculation as above in another CALCULATE and tag in a filter context of PREVIOUSDAY from the last date so this is basically getting the next to the last day.

In the RETURN statement, they check to see if a single value has been selected in the Time Range column in the TimeRange table. Probably a slicer. Maybe a disconnected table? If there is only one value, then it returns ACT variable.

If that is not the case, it gets the distinct values that have been selected and here I am fairly sure it just returns BLANK or an error all the time as it is unclear to that you can compare a table to a string. I have tested this and you cannot.


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Nice explanation @Greg_Deckler  got in there before me and with a more succinct answer than I had in my head 😊

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.