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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. 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
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.