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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Super User
Super User

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
Fabcon_Europe_Social_Bogo

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.