Forum Discussion
Percentage calculation with two date periods
- 1 year ago
Hi Anonymous
As I have replicated your scenario with the assuming sample data and attached the pbix file below.Assumed Period 1 (P1) and Period 2 (P2). I wanted to show the savings in € and %, depending on the date the user selects for each period.
Here's how I built it step-by-step without bookmarks, fully dynamic:- Created two separate slicers (Period1 and Period2) by making calculated tables from the main Date table:
DAX
CopyEdit
Period1 = DISTINCT('DateTable'[Date])
Period2 = DISTINCT('DateTable'[Date])
These slicers allow users to select two different dates freely.
- Captured the selected values from each slicer using measures:
DAX
CopyEdit
P1 Selected = MAX('Period1'[Date])
P2 Selected = MAX('Period2'[Date])
-
Created measures to calculate energy cost for each period:
DAX
CopyEdit
P1 Cost (€) = CALCULATE(SUM('Data'[Cost (€)]), 'Data'[Date] = [P1 Selected])
P2 Cost (€) = CALCULATE(SUM('Data'[Cost (€)]), 'Data'[Date] = [P2 Selected])
-
Calculated savings and % savings:
DAX
CopyEdit
Savings (€) = [P1 Cost (€)] - [P2 Cost (€)]
% Savings = DIVIDE([Savings (€)], [P2 Cost (€)], 0)
-
Added card visuals to show:
Total cost in P2 (baseline)
Total savings in €
% savings from P2
Added both slicers to the report so users can flexibly select any two periods to compare.
This setup gives a fully dynamic, user-driven way to compare any two dates without hardcoding periods or using bookmarks. It works great for trend analysis, energy savings, and cost comparisons. Hope this helps others trying to achieve something similar.
If the above information helps you, please give us a Kudos and marked the Accept as a solution.
Best Regards,
Community Support Team _ C Srikanth. - Created two separate slicers (Period1 and Period2) by making calculated tables from the main Date table:
I copied and pasted it again but there's another error message:
try this:
P1 Cost (€) = CALCULATE(SUM('Data'[Cost (€)]), filter('Data',[Date] = [P1 Selected]))
- Anonymous1 year agoNot applicable
It says that too few arguments were passed to the filter function, as the minimum argument count is 2
- Anonymous1 year agoNot applicable
It worked, I had forgotten the coma. Thanks!
- Vijay_Chethan1 year ago
Resolver III
are you sure you used same dax measure as above, i would say copy and paste it if you have manually typed
- Anonymous1 year agoNot applicable
Thank you very much! Vijay_Chethan v-csrikanth