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
PuneetSoni
Frequent Visitor

two months variance based on month selection in slicer

Can someone please help, i wanted to bring in another column which will show variance between two months selected from slicer.

 

PuneetSoni_0-1707097798906.png

 

8 REPLIES 8

Hi @PuneetSoni ,

Thanks for your feedback. Please try to delete the relationship between your fact table 'COMM_ANALYSIS' and Calendar table. Then check if you can get the desired result by the previous measures... Could you please grant me the proper permission to it since I can't access your shared file? Thank you.

vyiruanmsft_0-1707272154708.png

Max Month Value =
VAR _year =
SELECTEDVALUE ( 'Calendar'[Year] )
VAR _maxmonth =
MAX ( 'Calendar'[Month] )
RETURN
CALCULATE (
[Avg. Comm],
FILTER (
'Table',
YEAR ( 'COMM_ANALYSIS'[Date] ) = _year
&& MONTH ( 'COMM_ANALYSIS'[Date] ) = _maxmonth
),
ALL ( 'Calendar' )
)

2.
Min Month Value =
VAR _year =
SELECTEDVALUE ( 'Calendar'[Year] )
VAR _minmonth =
MIN ( 'Calendar'[Month] )
RETURN
CALCULATE (
[Avg. Comm],
FILTER (
'Table',
YEAR ( 'COMM_ANALYSIS'[Date] ) = _year
&& MONTH ( 'COMM_ANALYSIS'[Date] ) = _minmonth
),
ALL ( 'Calendar' )
)

3.
Variance = [Max Month Value]-[Min Month Value]


Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
PuneetSoni
Frequent Visitor

Thank you Rena. Appreciate your help. I am still not getting the desired results. Changed the Max Month and Min Month value but it is giving variance for same month. I am attaching a sample xl sheet data. All i want is i can select any two months from slicer and get the row wise variance for that.

PuneetSoni_0-1707233012074.png

I have two tables with below relationships

 

PuneetSoni_1-1707233064696.png

Also here are the three measures

1.
Max Month Value =
VAR _year =
SELECTEDVALUE ( 'Calendar'[Year] )
VAR _maxmonth =
MAX ( 'Calendar'[Month] )
RETURN
CALCULATE (
[Avg. Comm],
FILTER (
'Table',
YEAR ( 'Table'[Date] ) = _year
&& MONTH ( 'Table'[Date] ) = _maxmonth
),
ALL ( 'Calendar' )
)

2.
Min Month Value =
VAR _year =
SELECTEDVALUE ( 'Calendar'[Year] )
VAR _minmonth =
MIN ( 'Calendar'[Month] )
RETURN
CALCULATE (
[Avg. Comm],
FILTER (
'Table',
YEAR ( 'Table'[Date] ) = _year
&& MONTH ( 'Table'[Date] ) = _minmonth
),
ALL ( 'Calendar' )
)

3.
Variance = [Max Month Value]-[Min Month Value]

PuneetSoni
Frequent Visitor

Thank you both, i tried but i am getting same values in both measures. However, i should get previous month in Min Month value when selected from slicer. Here are my three measures-

1. 

Max Month Value =
var _max = MAXX(allselected('Calendar'[Month]), 'Calendar'[Month])
var _min = EOMONTH(_max, -1)

return
calculate([Avg. Comm], Filter('Calendar','Calendar'[Month] <=_max && 'Calendar'[Month] >=_min) )
 
2.
Min Month Value =
var _min = Minx(allselected('Calendar'[Month]), 'Calendar'[Month])
var _max = EOMONTH ( _min, 0)-- Here i tried -1 also but then Min Month value retuns is blank

return
calculate([Avg. Comm], Filter('Calendar','Calendar'[Month] <=_max && 'Calendar'[Month] >=_min) )
 
3.
Variance = [Max Month Value]-[Min Month Value]

PuneetSoni_0-1707153083731.png

 

Hi @PuneetSoni ,

According to your screenshot, it only select one option for Month slicer. Then Max Month Value and Min Month Value are the same. The variance will be 0. Do you want to get the variance when select the different two months in Month slicer? If yes, you can change the formula of your measures as below and check if you can get the expected result...

Max Month Value =
VAR _year =
    SELECTEDVALUE ( 'Calendar'[Year] )
VAR _maxmonth =
    MAX ( 'Calendar'[Month] )
RETURN
    CALCULATE (
        [Avg. Comm],
        FILTER (
            'Table',
            YEAR ( 'Table'[Date] ) = _year
                && MONTH ( 'Table'[Date] ) = _maxmonth
        ),
        ALL ( 'Calendar' )
    )
Min Month Value =
VAR _year =
    SELECTEDVALUE ( 'Calendar'[Year] )
VAR _minmonth =
    MIN ( 'Calendar'[Month] )
RETURN
    CALCULATE (
        [Avg. Comm],
        FILTER (
            'Table',
            YEAR ( 'Table'[Date] ) = _year
                && MONTH ( 'Table'[Date] ) = _minmonth
        ),
        ALL ( 'Calendar' )
    )

If the above one can't help you get the expected result, please provide some raw data in your tables (exclude sensitive data) with Text format and your expected result. It would be helpful to find out the solution. You can refer the following link to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
PuneetSoni
Frequent Visitor

Hi Amit,

Thanks for the quick reply. Yes i am using date calendar in my slicer. but it's giving me error in the date syntax in return section

 

PuneetSoni_0-1707142035890.png

 

amitchandak
Super User
Super User

@PuneetSoni , Hope you are using Date table in the slicer

 

You need measures like

 

Max Month Value =
var _max = Maxx(allselected(Date), Date[Date])
var _min = eomonoth(_max, -1)+1

return
calculate(Sum(Table[Value]), Filter(Date,Date[Date] <=_max && Date[Date] >=_min) )


Min Month Value =
var _min = Minx(allselected(Date), Date[Date])
var _max = eomonoth(_max, 0)

return
calculate(Sum(Table[Value]), Filter(Date,Date[Date] <=_max && Date[Date] >=_min) )


Varinace = [Max Month Value] - [Min Month Value]

@amitchandakThis looks pretty slick! I have a few questions if you wouldn't mind:

What's the reason for adding +1 below?

 

Max Month Value =
var _max = Maxx(allselected(Date), Date[Date])
var _min = eomonth(_max, -1)+1

return
calculate(Sum(Table[Value]), Filter(Date,Date[Date] <=_max && Date[Date] >=_min) )

 

Should _max be _min?


Min Month Value =
var _min = Minx(allselected(Date), Date[Date])
var _max = eomonth(_max, 0)

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.