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
mjanecek
Helper I
Helper I

Need Help with Dax

I have a measure (Avg Premium) that is filtered by month for all of 2022.  

 

Here is a visual of the months and that measure.

 

 

 

 

I am trying to write a measure that will allow me to pull out the month name and year of the month with the lowerst value of [Avg Premium].

 

I wrote the below measure, and its retrurning a value on the line with the month (2/22) with the lowest value of [Avg Premium], but Accouting month name and year are returning as 12(Dec) & 23, which is not even selected in the visual the MAXX statement is iterating though.  

 

testmonth =
    var premsum = SUMMARIZE(ALLSELECTED('Calendar'),'Calendar'[Accounting Month],"Avg Premium",[Avg Premium])
    var curprem = [Avg Premium]
    var minprem = MINX(premsum,[Avg Premium])
   
    RETURN  
 
     MAXX(
        FILTER(ALLSELECTED('Calendar'[Accounting Month]),
                curprem = minprem
              ),FORMAT('Calendar'[Accounting Month],"mm") & " " & FORMAT('Calendar'[Accounting Month],"yy")
                )
   

I need to figure out how to return the value of the accounting month and year on the line with the lowest value of the Avg Premium Measure.

 

 

 

 

1 ACCEPTED SOLUTION
ppm1
Solution Sage
Solution Sage

You can use a DAX pattern like this to return your max month in a card visual. Update it with your actual table, column, and measure names.

MaxMonth =
VAR vSummary =
    ADDCOLUMNS ( ALLSELECTED ( 'Date'[YearMonthShort] ), "cQty", [Total Qty] )
VAR vTop1 =
    TOPN ( 1, vSummary, [cQty], DESC )
RETURN
    MAXX ( vTop1, 'Date'[YearMonthShort] )

Pat

Microsoft Employee

View solution in original post

5 REPLIES 5
ppm1
Solution Sage
Solution Sage

You can use a DAX pattern like this to return your max month in a card visual. Update it with your actual table, column, and measure names.

MaxMonth =
VAR vSummary =
    ADDCOLUMNS ( ALLSELECTED ( 'Date'[YearMonthShort] ), "cQty", [Total Qty] )
VAR vTop1 =
    TOPN ( 1, vSummary, [cQty], DESC )
RETURN
    MAXX ( vTop1, 'Date'[YearMonthShort] )

Pat

Microsoft Employee

Can you tell me why my sort in the below code is not working right?

 

EVALUATE
VAR vSummary =
    ADDCOLUMNS ( ALLSELECTED  ( 'Calendar'[Accounting Month] ), "Prem", [Avg Premium] )
VAR vTop1 =
   
        TOPN ( 10 , vSummary,[Prem],DESC )
        
        
VAR vMaxmonth = maxx(vTop1,[Prem])
 RETURN vTop1
 

 

 

The premium clearly is not sorting the top 10 values in DESC order.  Have not been able to figure out why...

 

 

 

 

 

Thank you so much!  This works well.

 

 

Mikelytics
Resident Rockstar
Resident Rockstar

Hi @mjanecek ,

 

I tried to replicate your usecase. Please find a suggestion below.

 

My data model

Mikelytics_0-1673292045690.png

 

Formula Average

Average | Value = AVERAGE('Fact_Sales'[Values])

 

Formula Monthly Min Period

Iterator | Period with Min Value = 
var _current = [Average | Value]
var _MonthlyMinValue = 
    CALCULATE(
        MINX(
            VALUES(DimDate[MonthWithYear]),
            CALCULATE([Average | Value])
        ),
        ALLSELECTED(DimDate)
    )

Return

IF(_current=_MonthlyMinValue,SELECTEDVALUE(DimDate[MonthWithYear]))

 

Result

Mikelytics_1-1673292119931.png

 

Best regards
Michael
-----------------------------------------------------
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Appreciate your thumbs up!
@ me in replies or I'll lose your thread.

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

Hi: This works great when there is a month on a visual, but when I try to put it into a scorecard, I get no value.  How would I adapt the measure to allow the max month and year to display in a scorecard that did not have the month and year in the filter context.

 

 

 

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.