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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Diva20
Frequent Visitor

Help with Variance calculation with current month vs selected month from slicer

Hello All

 

Im trying to achieve a DAX expression to find the variance for the following below table:

 

variance.PNG

 

the formaula used in excel is 

Dec = $B$2-B2

Nov = $B$2-B3

Oct = $B$2-B4

Sep = $B$2-B5

Aug = $B$2-B6

 

Im currently using the follwoing measure and it doesnt work:

Variance P + Companies =
var prevmonth =
CALCULATE ( [Oppurtunities], DATEADD ( 'MasterData'[Date], -1, MONTH ) )
RETURN
IF (
ISBLANK (prevmonth),
0,
[Oppurtunities] - prevmonth
)

 

Can anyone help me out on the DAX expression with Variance calculation for current month vs selected month from slicer.

 

TIA 🙂

 

 

 

 

1 ACCEPTED SOLUTION
v-janeyg-msft
Community Support
Community Support

Hi, @Diva20 

 

It’s my pleasure to answer for you.

According to your description,You should have a date column or a date table, and your oppurtunities column seems to be a measure, so ,you can add a separate month column as a slicer through ‘enter data’,then create a measure to calculate the desired result.

Like this:

Variance P + Companies =
VAR a =
    SELECTEDVALUE ( 'Table (2)'[Month] )
VAR b =
    CALCULATE (
        [Measure],
        FILTER ( ALL ( 'Table' ), 'Table'[Month] = SELECTEDVALUE ( 'Table'[Month] ) )
    )
VAR c =
    CALCULATE (
        [Measure],
        FILTER (
            ALL ( 'Table' ),
            'Table'[Month] = SELECTEDVALUE ( 'Table (2)'[Month] )
        )
    )
RETURN
    IF ( ISBLANK ( [Measure] ), 0, c - b )

1.png

Here is my sample .pbix file.Hope it helps.

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-janeyg-msft
Community Support
Community Support

Hi, @Diva20 

 

It’s my pleasure to answer for you.

According to your description,You should have a date column or a date table, and your oppurtunities column seems to be a measure, so ,you can add a separate month column as a slicer through ‘enter data’,then create a measure to calculate the desired result.

Like this:

Variance P + Companies =
VAR a =
    SELECTEDVALUE ( 'Table (2)'[Month] )
VAR b =
    CALCULATE (
        [Measure],
        FILTER ( ALL ( 'Table' ), 'Table'[Month] = SELECTEDVALUE ( 'Table'[Month] ) )
    )
VAR c =
    CALCULATE (
        [Measure],
        FILTER (
            ALL ( 'Table' ),
            'Table'[Month] = SELECTEDVALUE ( 'Table (2)'[Month] )
        )
    )
RETURN
    IF ( ISBLANK ( [Measure] ), 0, c - b )

1.png

Here is my sample .pbix file.Hope it helps.

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Ashish_Mathur
Super User
Super User

Hi,

What do you mean by "for current month vs selected month from slicer"?  In the example that you have shown, what is the current month and what month have you chosen in the slicer?  Also, your base data should also have a Year column - I do not see that.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
AlB
Super User
Super User

Hi @Diva20 

You need to use DATEADD( ) on a well-constructed date table, not on your fact table. Are you doing that?

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.