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
Anonymous
Not applicable

DAX measure for price of bike in the last month of selected period

Hi,

If i have 2 or more Bike names and and i want to select the prize for last month of the selected period.

periodBike prizeName
1.20232,35,599Royal Enfield
2.20232,34,999Royal Enfield
3.20232,35,999Royal Enfield
4.20232,33,599Royal Enfield
5.20232,35,499Royal Enfield
6.20232,36,999Royal Enfield
7.20232,36,909Royal Enfield
8.20232,36,999Royal Enfield
   
1.20231,28,478BMW
2.20231,28,999BMW
3.20231,26,463BMW
4.20231,23,599BMW
5.20231,26,849BMW
6.20231,26,544BMW
7.20231,27,999BMW
8.20231,25,899BMW

For Example:- If i selected Royal enfield bike and the period is between 1.2023 to 5.2023 then the out put should be the last month of selected period.

 

5.20232,35,499Royal Enfield

Can someone help me to get the DAX formula for the above issue.

Thanks in advance.

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

It's a two step process. First find the max month of the selected period, then compute the value (via sum or max etc) for that month.

View solution in original post

3 REPLIES 3
sjoerdvn
Resolver III
Resolver III

Try something like:

Last Month Bike Prize = LASTNONBLANKVALUE(Table[period],MIN(Table[Bike prize]))
v-tangjie-msft
Community Support
Community Support

Hi @Anonymous ,

 

According to your description, here are my steps you can follow as a solution.

(1)My test data is the same as yours.

(2) Click "transform data" to enter the power query, click "Advanced Editor" to copy and paste the following code. Please check the steps in the right hand column.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZA9C8JADIb/itwcpL18XG4VHLu4OBwdBBWEorP/3lK5mogHboHnyZvwlhL6bewiBggRkIFznsfD43maNvv79XaZzmGEEqKxCHLDQpfVsshY2LzILosalhhLmheTt7rflv6VtfbVQ1SgpPO4G46+pYW9EypDwwRI0DAyrDZSGbs9JcvEMSYyLBmWvn5Rwxj0w8YX", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [period = _t, #"Bike prize" = _t, Name = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"period", type number}, {"Bike prize", Int64.Type}, {"Name", type text}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "period", "period - Copy"),
    #"Split Column by Delimiter" = Table.SplitColumn(Table.TransformColumnTypes(#"Duplicated Column", {{"period - Copy", type text}}, "en-US"), "period - Copy", Splitter.SplitTextByDelimiter(".", QuoteStyle.Csv), {"period - Copy.1", "period - Copy.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"period - Copy.1", Int64.Type}, {"period - Copy.2", Int64.Type}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{{"period - Copy.2", "Year"}, {"period - Copy.1", "Month"}}),
    #"Added Custom" = Table.AddColumn(#"Renamed Columns", "Custom", each 1),
    #"Renamed Columns1" = Table.RenameColumns(#"Added Custom",{{"Custom", "Day"}}),
    #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Renamed Columns1", {{"Year", type text}, {"Month", type text}, {"Day", type text}}, "en-US"),{"Year", "Month", "Day"},Combiner.CombineTextByDelimiter("-", QuoteStyle.None),"Merged"),
    #"Changed Type2" = Table.TransformColumnTypes(#"Merged Columns",{{"Merged", type date}}),
    #"Renamed Columns2" = Table.RenameColumns(#"Changed Type2",{{"Merged", "Year-Month"}}),
    #"Changed Type3" = Table.TransformColumnTypes(#"Renamed Columns2",{{"period", type text}})
in
    #"Changed Type3"

vtangjiemsft_0-1695620164822.png

(3)We can create a measures. 

Flag = IF(YEAR(MAX('Table'[Year-Month]))=YEAR(MAXX(ALLSELECTED('Table'),'Table'[Year-Month])) && MONTH(MAX('Table'[Year-Month]))=MONTH(MAXX(ALLSELECTED('Table'),'Table'[Year-Month])),1,0)
Bike prize Measure = CALCULATE(MAX('Table'[Bike prize]),FILTER(ALLSELECTED('Table'),[Flag]=1))

(4)Place [Flag]=1 on the visual object filter and then the result is as follows.

vtangjiemsft_1-1695620281247.png

Best Regards,

Neeko Tang

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

lbendlin
Super User
Super User

It's a two step process. First find the max month of the selected period, then compute the value (via sum or max etc) for that month.

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.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

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