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!

Proud to be a Super User!

Website   YouTube    LinkedIn

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!

Proud to be a Super User!

Website   YouTube    LinkedIn

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
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Get Ready for Power BI Dev Camp

Power BI Dev Camp - June 24th

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors
Top Kudoed Authors