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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
mmilicic
Frequent Visitor

Get value from first period applied on every other period

Hello Comunity,

 

I have a table and I am trying to get first value of the column "Period_Up_Today", but I can not reach it.

 

mmilicic_0-1656832881465.png

 

If anyone could help I will really appriciate it.

 

Thanks,

Mario

 

1 ACCEPTED SOLUTION
tackytechtom
Super User
Super User

Hi @mmilicic ,

 

Here a solution in DAX with a calculated column:

tomfox_0-1656834693265.png

 

Here the DAX code:

Column = 
VAR _earliestDate = CALCULATE ( MINX ( ALL ( Table ), Table[Period_Up_Today] ) )
RETURN
CALCULATE ( MINX ( ALL ( Table ), Table[Amount] ), Table[Period_Up_Today] = _earliestDate ) 

 

Let me know if this helps, or if you'd like a solution in Power Query 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

4 REPLIES 4
tackytechtom
Super User
Super User

Hi @mmilicic ,

 

How about this :

tomfox_0-1656839123523.png

 

 

Here the M that you can paste into the advanced editor:

tomfox_1-1656839186150.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fcyxDcAgDETRXVyDdDaQQMkciP3X4JwiHe5+8fTXkjmnJDGYZvS/BksB2ekiFF9FQlklFMaqd2EZ/mih8McTisJ6Q1FZPRSNNVzsAw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Constant Period 1" = _t, Period_Up_Today = _t, Amount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Constant Period 1", type date}, {"Period_Up_Today", type date}, {"Amount", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"MinDate", each List.Min([Period_Up_Today]), type nullable date}, {"AllRows", each _, type table [ID=nullable text, Constant Period 1=nullable date, Period_Up_Today=nullable date, Amount=nullable number]}}),
    #"Expanded AllRows" = Table.ExpandTableColumn(#"Grouped Rows", "AllRows", {"Period_Up_Today", "Amount"}, {"AllRows.Period_Up_Today", "AllRows.Amount"}),
    #"Added Custom" = Table.AddColumn(#"Expanded AllRows", "FilterColumn", each if [MinDate] = [AllRows.Period_Up_Today] then 1 else 0),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([FilterColumn] = 1)),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"ID"}, #"Filtered Rows", {"ID"}, "Filtered Rows", JoinKind.LeftOuter),
    #"Expanded Filtered Rows" = Table.ExpandTableColumn(#"Merged Queries", "Filtered Rows", {"AllRows.Amount"}, {"Filtered Rows.AllRows.Amount"})
in
    #"Expanded Filtered Rows"

Does this fix your issue? 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

tackytechtom
Super User
Super User

Hi @mmilicic ,

 

Here a solution in DAX with a calculated column:

tomfox_0-1656834693265.png

 

Here the DAX code:

Column = 
VAR _earliestDate = CALCULATE ( MINX ( ALL ( Table ), Table[Period_Up_Today] ) )
RETURN
CALCULATE ( MINX ( ALL ( Table ), Table[Amount] ), Table[Period_Up_Today] = _earliestDate ) 

 

Let me know if this helps, or if you'd like a solution in Power Query 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

All good, this works good.

Thanks 😄

Hi Tom,

 

Thanks 😄

 

Can you please show me the solution in Query?

I have a big dataset so maybe I can not get the result because of that.

 

All the best,

Mario

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.