Forum Discussion
Calculating daily differences
- 5 years ago
Hi ripstaur ,
First create an index column;
Then create a column as below:
Daily Cases = VAR _maxvalue = CALCULATE ( MAX ( 'Table'[Cases] ), FILTER ( 'Table', 'Table'[County] = EARLIER ( 'Table'[County] ) && 'Table'[Index] < EARLIER ( 'Table'[Index] ) ) ) RETURN 'Table'[Cases] - _maxvalueAnd you will see:
For the related .pbix file,pls see attached.
Best Regards,
KellyDid I answer your question? Mark my reply as a solution!
Hi ripstaur ,
First create an index column;
Then create a column as below:
Daily Cases =
VAR _maxvalue =
CALCULATE (
MAX ( 'Table'[Cases] ),
FILTER (
'Table',
'Table'[County] = EARLIER ( 'Table'[County] )
&& 'Table'[Index] < EARLIER ( 'Table'[Index] )
)
)
RETURN
'Table'[Cases] - _maxvalue
And you will see:
For the related .pbix file,pls see attached.
Best Regards,
Kelly
Did I answer your question? Mark my reply as a solution!
Thanks, Kelly! This worked like a charm. I'm still trying to make a PowerQuery solution work, but this DAX solution is absolutely one great solution. My question now becomes - which is a more efficient solution--the DAX modeling or a PowerQuery one, if we can figure it out? I am going to replicate this for the number of deaths per county as well. Since there are about 3400 counties in the US, and the daily report also include extras (e.g., US territory counts, counts of cases that were reported without a county affiliation), I add 3400+ new records every day , with a State column, a county column, a lat and long column, a FIPS column, cumulative cases, cumulative deaths, daily cases and daily deaths. So would it be more efficient to do this in modeling, or querying?
Best regards,
Rip