Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi All,
I have table structure like following:
Date | Customer | Price |
1-1-2021 | AA | 10 |
1-2-2021 | AA | 10 |
1-3-2021 | AA | 11 |
1-4-2021 | AA | 10 |
1-5-2021 | AA | 10 |
1-6-2021 | AA | 10 |
and I have to create the following table:
Customer | Price | Duration in days |
AA | 10 | 2 |
AA | 11 | 1 |
AA | 10 | 3 |
Thank you for your help!
Solved! Go to Solution.
@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"
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
@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"
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
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.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
106 | |
93 | |
75 | |
62 | |
50 |
User | Count |
---|---|
147 | |
107 | |
105 | |
87 | |
61 |