cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MrMP
Helper I
Helper I

List how long price was active

Hi All,

 

I have table structure like following:

DateCustomerPrice
1-1-2021AA10
1-2-2021AA10
1-3-2021AA11
1-4-2021AA10
1-5-2021AA10
1-6-2021AA10

and I have to create the following table:

 

CustomerPriceDuration in days
AA102
AA111
AA103

 

Thank you for your help!

1 ACCEPTED SOLUTION
Fowmy
Super User IV
Super User IV

@MrMP 

You can do it in Power Query with a single Group By step. After you group by selecting Customer and Price, add this ", GroupKind.Local" at the end of the group by step.

You can paste the code given below on a Blank Query and check.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ11DUyMDJU0lFydAQShgZKsTogYSPswsaowoZQYRPsqk2xC5thCMcCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Customer = _t, Price = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Customer", type text}, {"Price", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Customer", "Price"}, {{"Count", each Table.RowCount(_), Int64.Type}}, GroupKind.Local)
in
    #"Grouped Rows"

 

Fowmy_0-1619463814883.png

 

 

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Blog - Data Visualization

Website   YouTube    LinkedIn   PBI User Group

View solution in original post

2 REPLIES 2
Fowmy
Super User IV
Super User IV

@MrMP 

You can do it in Power Query with a single Group By step. After you group by selecting Customer and Price, add this ", GroupKind.Local" at the end of the group by step.

You can paste the code given below on a Blank Query and check.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ11DUyMDJU0lFydAQShgZKsTogYSPswsaowoZQYRPsqk2xC5thCMcCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Customer = _t, Price = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Customer", type text}, {"Price", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Customer", "Price"}, {{"Count", each Table.RowCount(_), Int64.Type}}, GroupKind.Local)
in
    #"Grouped Rows"

 

Fowmy_0-1619463814883.png

 

 

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Blog - Data Visualization

Website   YouTube    LinkedIn   PBI User Group

View solution in original post

Thank you.

Is there a chance for this to be dynamic or in dax, since number of dimensions can vary. Sometimes its only a customer, sometimes its customer and product.

Helpful resources

Announcements
MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

July 2021 Update 768x460.png

Check it out!

Click here to read more about the July 2021 Updates

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Urdu Hindi D365 Bootcamp 768x460.png

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

Top Solution Authors
Top Kudoed Authors