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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
Super User
Super User

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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