cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
gabrieldkvl
Frequent Visitor

How to get the top 1 value based on date range

Hello everyone!

 

I have a date range between 2017 and 2022. I would like to now what month and year the higher value happened.

 

I had to divide the values to get an average based on USD and m3.

 

USD/m³ = CALCULATE (
    SUM ( 'Base 02'[Reached] ),
    'Base 02'[KPI] = "USD"
)
    / CALCULATE (
    SUM ( 'Base 02'[Reached] ),
    'Base 02'[KPI] = "m³"
) 

 

 Then I created another measure to get the MAX of USD/m3 ignoring the month and year filters.

 

MAX USD/m³ = 
VAR SelectedMax =
    CALCULATE (
        MAXX (
            VALUES ( 'Base 02'[Year and Month] ),
            'Calculations Base 02'[USD/m³] 
        ),
        ALLSELECTED ( 'Base 02'[Year and Month] )
    )
RETURN
    SelectedMax

 

 The result was successfully displayed. But I don't know how to add the year and month when this value happened.

 

The currently result is: 1.265.03

I would like something like: 1.265.03  Mar/2020

 

My year and month table contains the right format of date and it contains a typical hierarchy of calendar.

 

Thanks in advance.

2 REPLIES 2
v-shex-msft
Community Support
Community Support

Hi @gabrieldkvl,

Can you please share a pbix or some dummy data that keep the raw data structure with expected results? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
daXtreme
Solution Sage
Solution Sage

Hi @gabrieldkvl 

 

First, you never put table name in front of a measure and there's a very good reason not to do so. Please follow the sacred tradition of DAX developers.

 

Second, you want to return text, not a number (are you aware of that?). Third, to do what you want you should use the TOPN function and/or ADDCOLUMNS. In the latter case you should then filter for the highest value of the measure and use CONCATENATE(X) on the row(s) returned. There can be more than 1 row returned with the highest value, hence CONCATENATEX.

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors