Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
I am trying to create a calculation to show percent change over time using a date column that is not a continuous date. The data shows total file sizes each time a report is run, but the report can be run on demand so attempts to use functions like PREVIOUSDAY don't really work for me because there are missing days.
DataUsage
Size | ReportDate |
100 | 10/1/2021 |
50 | 10/4/2021 |
25 | 10/7/2021 |
75 | 10/15/2021 |
50 | 10/17/2021 |
125 | 10/18/2021 |
150 | 10/20/2021 |
100 | 10/22/2021 |
Given the information above, can anyone tell me the best way to create a table similar to this?
ReportDate | Size | Change (Current Size - Previous Size) | Percent Change (Change / Previous Size) |
10/1/2021 | 100 | ||
10/4/2021 | 50 | -50 | -50% |
10/7/2021 | 25 | -25 | -50% |
10/15/2021 | 75 | 50 | 200% |
10/17/2021 | 50 | -25 | -33% |
10/18/2021 | 125 | 75 | 150% |
10/20/2021 | 150 | 25 | 20% |
10/22/2021 | 100 | -50 | -33% |
For background, I've attempted a variety ways to get at this calculation without success which I'll outline below.
I created a dates table and a previous date column:
Solved! Go to Solution.
Hi, @mrLeyshock ;
You could modify the measure as follows:
Percent Change =
var _pre=MAXX(FILTER(ALL('Table'),[ReportDate]= CALCULATE(MAX([ReportDate]),FILTER(ALL('Table'),[ReportDate]<MAX('Table'[ReportDate])))),[Size])
return DIVIDE(MAX([Size])- _pre,_pre)
The final output is shown below:
Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @mrLeyshock ;
You could modify the measure as follows:
Percent Change =
var _pre=MAXX(FILTER(ALL('Table'),[ReportDate]= CALCULATE(MAX([ReportDate]),FILTER(ALL('Table'),[ReportDate]<MAX('Table'[ReportDate])))),[Size])
return DIVIDE(MAX([Size])- _pre,_pre)
The final output is shown below:
Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thank you for sharing this. It was exactly what I needed.
To close the loop in this. The example that you provided was perfect for the data sample that I shared. Of course my data was a bit more complex, rather than one row per date with a size value, I actually have many smaller size values for each date that I needed to sum. I was ale to modify the example to make it work.
--CREATED AS A COLUMN
PreviousDate =
VAR _ReportDate = DataUsage[ReportDate]
VAR _prevDate = CALCULATE(MAX(DataUsage[ReportDate]), FILTER(DataUsage,DataUsage[ReportDate] < _ReportDate))
RETURN
_prevDate
--MEASURES
PreviousSize =
SUMX (
FILTER (
ALL ( 'DataUsage' ),
[ReportDate]
= CALCULATE (
MAX ( [ReportDate] ),
FILTER (
ALL ( 'DataUsage' ),
[ReportDate] < MAX ( 'DataUsage'[ReportDate] )
)
)
),
[Size]
)
PercentChange = DIVIDE([CurrentSize]-[PreviousSize], [PreviousSize])
Here's previous size as a column.
PreviousValue =
VAR _ReportDate = DataUsage[ReportDate]
VAR _prevDate = CALCULATE(MAX(DataUsage[ReportDate]), FILTER(DataUsage,DataUsage[ReportDate] < _ReportDate))
RETURN
CALCULATE(SUM(DataUsage[Size]), FILTER(DataUsage,DataUsage[ReportDate] = _prevDate))
Is that enough to get you started?
User | Count |
---|---|
140 | |
113 | |
104 | |
77 | |
64 |
User | Count |
---|---|
135 | |
118 | |
101 | |
71 | |
61 |