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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
trupac
Frequent Visitor

Formula is summing instead of giving variance

Hi, 

 

I am trying to get a week to week variance and I tried using this measure but it looks like it's just adding all the volumes for a total of 1478.92 BOE instead of giving me the difference week to week:

 

Variance = CALCULATE(SUM('TDAILY_WELL_TNX (2)'[TOTAL NET BOE]), DATESBETWEEN('TDAILY_WELL_TNX (2)'[PRODUCTION_DATE],TODAY()-15,TODAY()-8)) - CALCULATE(SUM('TDAILY_WELL_TNX (2)'[TOTAL NET BOE]), DATESBETWEEN('TDAILY_WELL_TNX (2)'[PRODUCTION_DATE],TODAY()-7,TODAY()))
 
Screenshot 2024-05-30 093248.png
2 ACCEPTED SOLUTIONS
jgeddes
Super User
Super User

At quick glance it appears that there is no way for your measure to calculate for the context supplied by the 'Production_Date' in your visuals.
You will likely have to replace the instances of 'Today()' with a reference to the 'Production_Date' context.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

Anonymous
Not applicable

Hi @trupac ,

Agree with jgeddes. Try adding a calendar table:

Calendar = CALENDAR(MIN('TDAILY_WELL_TNX (2)'[PRODUCTION_DATE]), MAX('TDAILY_WELL_TNX (2)'[PRODUCTION_DATE]))

vcgaomsft_0-1717395223760.png

And please try:

Variance = 
VAR __cur_date = SELECTEDVALUE('Calendar'[Date])
VAR __result =
CALCULATE (
    SUM ( 'TDAILY_WELL_TNX (2)'[TOTAL NET BOE] ),
    DATESBETWEEN (
        'Calendar'[Date],
        __cur_date - 15,
        __cur_date - 8
    )
)
    - CALCULATE (
        SUM ( 'TDAILY_WELL_TNX (2)'[TOTAL NET BOE] ),
        DATESBETWEEN ( 'Calendar'[Date], __cur_date - 7, __cur_date )
    )
RETURN
__result

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @trupac ,

Agree with jgeddes. Try adding a calendar table:

Calendar = CALENDAR(MIN('TDAILY_WELL_TNX (2)'[PRODUCTION_DATE]), MAX('TDAILY_WELL_TNX (2)'[PRODUCTION_DATE]))

vcgaomsft_0-1717395223760.png

And please try:

Variance = 
VAR __cur_date = SELECTEDVALUE('Calendar'[Date])
VAR __result =
CALCULATE (
    SUM ( 'TDAILY_WELL_TNX (2)'[TOTAL NET BOE] ),
    DATESBETWEEN (
        'Calendar'[Date],
        __cur_date - 15,
        __cur_date - 8
    )
)
    - CALCULATE (
        SUM ( 'TDAILY_WELL_TNX (2)'[TOTAL NET BOE] ),
        DATESBETWEEN ( 'Calendar'[Date], __cur_date - 7, __cur_date )
    )
RETURN
__result

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

Hi gao, thank you for the descriptive response. 

 

This might be a dumb question but I realize the code you gave me is not just a basic formula, looks more like SQL, where do I type the code in to get the results? I broke down the code by separating it out as formulas in my Calendar table but it didn't return the correct results.

 

Screenshot 2024-06-03 080812.pngScreenshot 2024-06-03 080754.png

 

 

Anonymous
Not applicable

Hi @trupac ,

This is a measure and you can create it here:

vcgaomsft_0-1717462285249.png

Best Regards,
Gao

Community Support Team

jgeddes
Super User
Super User

At quick glance it appears that there is no way for your measure to calculate for the context supplied by the 'Production_Date' in your visuals.
You will likely have to replace the instances of 'Today()' with a reference to the 'Production_Date' context.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors