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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
edlng
Helper I
Helper I

Percentage calculation with two date periods

Hi!

I'm newly using PowerBI and I've been struggling on obtaining some comparative and percentage values.

 

The data I have is an energy cost per month on three sites, for two energy types.

I created a slicer for my first period (P1) and a second for the period I want to compare it with (P2). The date periods are not limited to specific ones, they can be adjusted freely.

 

I would like to calculate the savings in € and % in P1 compared with P2.
The results I want to obtain are:

- total cost without savings

- total savings in €

- % savings from last year total cost

 

Do you know how I could do that?

Thank you so much!

1 ACCEPTED SOLUTION
v-csrikanth
Community Support
Community Support

Hi @edlng 
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:

  1. 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.

  2. Captured the selected values from each slicer using measures:

    DAX

    CopyEdit

    P1 Selected = MAX('Period1'[Date])

    P2 Selected = MAX('Period2'[Date])

  3. 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])

  4. Calculated savings and % savings:

    DAX

    CopyEdit

    Savings (€) = [P1 Cost (€)] - [P2 Cost (€)]

    % Savings = DIVIDE([Savings (€)], [P2 Cost (€)], 0)

  5. 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.

 

View solution in original post

12 REPLIES 12
v-csrikanth
Community Support
Community Support

Hi @edlng 
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:

  1. 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.

  2. Captured the selected values from each slicer using measures:

    DAX

    CopyEdit

    P1 Selected = MAX('Period1'[Date])

    P2 Selected = MAX('Period2'[Date])

  3. 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])

  4. Calculated savings and % savings:

    DAX

    CopyEdit

    Savings (€) = [P1 Cost (€)] - [P2 Cost (€)]

    % Savings = DIVIDE([Savings (€)], [P2 Cost (€)], 0)

  5. 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.

 

Hello @v-csrikanth
I have a problem with the results for the savings formula: Savings (€) = [P1 Cost (€)] - [P2 Cost (€)]
The total result is additioning the total cost for both periods, but it's not calculating the difference between the two years.
What I wish to have is the savings for P1, and P2 to be implicit. Like: "1 | Gas | 2024 | -4,254,125€"
Shouldn't there be a relationship between the two periods in the formula for it to happen?

edlng_0-1748352355762.png

 

Hi @v-csrikanth, thank you for your answer!
I got this error message when trying to write this measure "P1 Cost (€) = CALCULATE(SUM('Data'[Cost (€)]), 'Data'[Date] = [P1 Selected])". Do you know what went wrong?

edlng_0-1747393761649.png

 

Thank you!

you missed bracket for sum function

I copied and pasted it again but there's another error message:

edlng_0-1747395043698.png

 

try this:
P1 Cost (€) = CALCULATE(SUM('Data'[Cost (€)]), filter('Data',[Date] = [P1 Selected]))

It says that too few arguments were passed to the filter function, as the minimum argument count is 2

It worked, I had forgotten the coma. Thanks!

are you sure you used same dax measure as above, i would say copy and paste it if you have manually typed

 

Thank you very much! @Vijay_Chethan @v-csrikanth 

Vijay_Chethan
Super User
Super User

hello edlng,
might be really helpful if you could provide some test data to understand your usecase better

 

Hi @Vijay_Chethan 

Yes of course, here's a sample: 

Site IdYearEnergy IdEnergy typeCost
120201Electricity €          217.201,00
120202Gas €           42.222,00
220201Electricity €         424.204,00
220202Gas €           42.404,00
320201Electricity €          442.112,00
320202Gas €           32.442,00
120211Electricity €           144.011,00
120212Gas €            14.044,00
220211Electricity €           114.011,00
220212Gas €           24.227,00
320211Electricity €          145.712,00
320212Gas €             14.751,00

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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