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

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.

 period Bike prize Name 1.2023 2,35,599 Royal Enfield 2.2023 2,34,999 Royal Enfield 3.2023 2,35,999 Royal Enfield 4.2023 2,33,599 Royal Enfield 5.2023 2,35,499 Royal Enfield 6.2023 2,36,999 Royal Enfield 7.2023 2,36,909 Royal Enfield 8.2023 2,36,999 Royal Enfield 1.2023 1,28,478 BMW 2.2023 1,28,999 BMW 3.2023 1,26,463 BMW 4.2023 1,23,599 BMW 5.2023 1,26,849 BMW 6.2023 1,26,544 BMW 7.2023 1,27,999 BMW 8.2023 1,25,899 BMW

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.2023 2,35,499 Royal Enfield

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

Thanks in advance.

1 ACCEPTED SOLUTION
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.

3 REPLIES 3
Super User

Try something like:

``Last Month Bike Prize = LASTNONBLANKVALUE(Table[period],MIN(Table[Bike prize]))``
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"``````

(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.

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.

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

#### 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 Monthly Update - June 2024

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

#### 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.

#### New forum boards available in Real-Time Intelligence.

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

Top Solution Authors
Top Kudoed Authors