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
Anonymous
Not applicable

Relative Date Calculations Using Variables

Hi All,

 

Trying to come up with a series of measures which could accomplish the following

1. Sum of Quantity of Previous 1 Month (from a given date) * weight factor (1.2)

2. Sum of Quanity of Previous 3 Months (from the same date) * weight factor (0.8)

3. Sum of Quantity of Previous 6 Months (from the same date) * weight factor (0.6)

4. Sum of Quantity of Previous 12 Months (from the same date)* weight factor (0.4)

5. Can Plot values from past 13 months with each month displaying value of Sum (Item 1. through Item 4.)

 

It seems I am able to calculate the values, but the graph is not displaying the correct values for all of the months.

dankuehn_0-1644700688786.png

 

Basically I am using a series of formulas like below and adding them together

QtyTotal1Month = 
Var CurrentDate = MIN('Date'[Date])
Return
CALCULATE(
                    'Date'[Total Qty] // This is a Sum of the Total Quantity
                        ,ALL('Date'[Date])
                        ,'Date'[Date] <=EOMONTH(CurrentDate,0),Date[Date]>EOMONTH(CurrentDate,-1))*12*0.1 // The -1 would then be replaced by -3,-6,-12 in other formulas

Resulting Graph - Stops at April even though technically my values for March would still not be 0.  Any help is appreciated. 

dankuehn_1-1644701197386.png

 

4 REPLIES 4
Anonymous
Not applicable

Please Try this measure
Note:- This measure for only last month for more use can change -1 to -3,-6, and more.
        

Measure1 =
VAR P_ONEMONTH =
    CALCULATE (
        SUM ( 'Date'[Total Qty] ),
        DATEADD ( 'Date'[Date], -1, MONTH )
    )
RETURN
    P_ONEMONTH * 0.8

  :- When you put this measure into a line graph the first month does not appear because the first month did not contain data to show that month you can use this measure.

Measure =
VAR P_OneMonth =
    CALCULATE (
        SUM ( 'Date'[Total Qty] ),
        DATEADD ( 'Date'[Date], -1, MONTH )
    )
VAR Result = one * 0.8
RETURN
    IF ( Result = BLANK (), 0, Result )

If I did not get your requirement please correct me.

Anonymous
Not applicable

Hello Vairag99 - I now realize my problem is that I do not have specific rows for every month which contain rejects for that specific vendor.  When I try to apply a filter for the vendor on my PBI Visuals, it does not perform the calculations for those vendors for those months because no rows exist for that month and vendor even if the measure output is not 0.  PBI does not have any existing relationship for those months and that vendor.  I still do not know how to solve this problem

Anonymous
Not applicable

This did not work - I will post more information as well as trying a different route to add dates.

lbendlin
Super User
Super User

Please provide sanitized sample data that fully covers your issue. If you paste the data into a table in your post or use one of the file services it will be easier to work with. Please show the expected outcome.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

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.