Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

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 cre...
  • v-csrikanth's avatar
    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:

    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.