Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi, I'm having a play with the COVID-19 dataset from Johns Hopkins, and trying to figure out how I can see the number of new cases from the previous day so I can plot something like the graph below from the Guardian.
I followed this tutorial to get my dataset, so I have a big table with State, Country, Date, Value columns.
Each State/Country combination has a row for each date eg: Victoria/Australia has a row for every date with that days cumulative total, as does New South Wales/Australia.
However, not every row has a State eg: New Zealand only has country, State is Blank.
Essentially what I want to do is to add a new column, Increase, and for each row calculate the difference between "Value" from that row and the row which matches the State & Country columns, but the previous days date.
NOTE: THis is not actual code!! Just a representation of what I'm looking for...
ie: this.Increase = this.Value - FindRow(State = this.State && Country = this.Country & Date - this.Date - 1).Value
I have no idea where to start!! Please help!!
FYI: I'm not a real data analyst, just a geek with Power BI looking to kill some time this weekend while I stay home!
Solved! Go to Solution.
Hi @Anonymous ,
Please try the DAX like below:
Daily cases =
VAR __CountyName = 'COVID'[County Name]
VAR __State = 'COVID'[State]
VAR __Yesterday = DATEADD(COVID[Date],-1,DAY)
VAR __TodaysCases = 'COVID'[Cases]
RETURN __TodaysCases - CALCULATE(
SUM('COVID'[Cases]) ,
FILTER(
COVID,
COVID[Date] = __Yesterday &&
COVID[County Name] = __CountyName &&
COVID[State] = __State
)
) + 0
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Anonymous ,
Please try the DAX like below:
Daily cases =
VAR __CountyName = 'COVID'[County Name]
VAR __State = 'COVID'[State]
VAR __Yesterday = DATEADD(COVID[Date],-1,DAY)
VAR __TodaysCases = 'COVID'[Cases]
RETURN __TodaysCases - CALCULATE(
SUM('COVID'[Cases]) ,
FILTER(
COVID,
COVID[Date] = __Yesterday &&
COVID[County Name] = __CountyName &&
COVID[State] = __State
)
) + 0
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Anonymous ,
In this case the best option is not to adda new column but a calculated measure. Since measures are calculated based on context if you add the country or the state, or the full dataset the calculation will adjust accordingly.
Try something similar to:
Increase =
SUM ( Table[Column] )
- CALCULATE (
SUM ( Table[Column] );
FILTER ( ALL ( Table[Date] ); Table[Date] = MAX ( Table[Date] ) - 1 )
)
Replace the Tables and column names by the ones in your report.
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsCovering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
113 | |
97 | |
85 | |
70 | |
61 |
User | Count |
---|---|
151 | |
121 | |
104 | |
87 | |
67 |