Thursday, April 25, 2024

How to repeat the List of items for each Category using Power Query

How to repeat the List of items for each Category using M-Query in Power BI
Scenario:
Suppose we have the sample of Product details as per below. In this sample we have 10 distinct Products and 3 unique Product Segments.
From this sample, we need to repeat the list of Products for each Product Segment.


We can achieve this Scenario, using the following M-Query (Power Query):

ProdListBySegment =
let
    Source = Product_Details,
    ProdSegmentList = List.Distinct(Source[Prod_Segment]),
    ProdNameList = List.Repeat(List.Distinct({Source[Prod_Name]}), List.Count(ProdSegmentList)),
    TableFromProdLists = Table.FromColumns(ProdNameList, ProdSegmentList)
in
    TableFromProdLists

Result:

Please Note:
I used above sample only to explain how this technique works. 
You can apply this technique for the right Scenario.

Thanks, Tamatam

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.

Featured Post from this Blog

How to compare Current Snapshot Data with Previous Snapshot in Power BI

How to Dynamically compare two Snapshots Data in Power BI Scenario: Suppose, we have a sample Sales data, which is stored with Monthly Snaps...

Popular Posts from this Blog