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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Monthly variance

Hi everyone 

 

Need help... I am new to DAX and trying to calculate the monthly variance for a graph. Would like to be able to do this calculation in PBI itself. Currently it's being done on excel before the file is imported. 

 

I'd like to create a column like the one highlighted in yellow: 

msfer_0-1637628382859.png

 

Thank you 

1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@Anonymous 

you can create a date column and create a variance column.

date = date(left('Table'[Year month],4),RIGHT('Table'[Year month],2),1)

Column = 
VAR _last=maxx(FILTER('Table','Table'[platfrom]=EARLIER('Table'[platfrom])&&'Table'[date]=EDATE(EARLIER('Table'[date]),-1)),'Table'[coverage])
return if(ISBLANK(_last),BLANK(),('Table'[coverage]-_last))

pls see the attachment below





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

Proud to be a Super User!




View solution in original post

4 REPLIES 4
Nathaniel_C
Community Champion
Community Champion

Hi @Anonymous ,
Please try this:

Variance =
VAR _curDate =
    MAX ( myTable[YearMonth] )
VAR _curPlatform =
    MAX ( myTable[Platform] )
VAR _prevDate =
    MAX ( myTable[YearMonth] ) - 1
VAR _curValue =
    MAX ( myTable[Value] )
VAR _minDate =
    CALCULATE ( MIN ( myTable[YearMonth] ), ALL () )
VAR _prevValue =
    CALCULATE (
        MAX ( myTable[Value] ),
        FILTER (
            ALL ( myTable ),
            myTable[YearMonth] = _prevDate
                && myTable[Platform] = _curPlatform
        )
    )
VAR _variance = _prevValue - _curValue
RETURN
    IF ( _minDate = MAX ( myTable[YearMonth] ), 0, _variance )

 

dd.PNG


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





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

Proud to be a Super User!




ryan_mayu
Super User
Super User

@Anonymous 

you can create a date column and create a variance column.

date = date(left('Table'[Year month],4),RIGHT('Table'[Year month],2),1)

Column = 
VAR _last=maxx(FILTER('Table','Table'[platfrom]=EARLIER('Table'[platfrom])&&'Table'[date]=EDATE(EARLIER('Table'[date]),-1)),'Table'[coverage])
return if(ISBLANK(_last),BLANK(),('Table'[coverage]-_last))

pls see the attachment below





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

Proud to be a Super User!




Anonymous
Not applicable

Perfect! Thanks @ryan_mayu 

you are welcome





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

Proud to be a Super User!




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.