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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Asingh31
Frequent Visitor

Measure to sum up the combinations from other rows

Asingh31_0-1737027513843.png

Hi,

Could someone please help me in creating the measure for this calculation.
Product Column is  a combination of products.
For eg. Product 1 and Product 2 are as a combination in 3 rows ( 1 ,2, 3) that's why sum 18.

ProductCount
Product 1 , Product 210
Product 1 , Product 2, Product 35
Product 2, Product 312
Product 1 , Product 2, Product 3, Product 4     3
Product 1 , Product 315


Best,
AS

1 ACCEPTED SOLUTION

FilteredProduct = 
VAR productcount =
    COUNTROWS ( Split2 )
RETURN
    productcount
        <= CALCULATE (
            COUNTROWS ( Split ),
            KEEPFILTERS (
                Split[Individual Products] IN VALUES ( Split2[Individual Products] )
            )
        )

VAR productcount:

Counts the number of rows in the Split2 table within the current filter context., ie based on the slicer selection from Split2

 

RETURN Statement:

Compares productcount with the result of the CALCULATE function:

  • COUNTROWS(Split): Counts the rows in the Split table.
    KEEPFILTERS with IN VALUES: Ensures that the filter from Split2[Individual Products] is applied to
  • Split[Individual Products], so only rows with matching products are considered.
    The measure returns TRUE if the row count in Split2 (productcount) is less than or equal to the filtered row count in Split. Otherwise, it returns FALSE.
Total in Split2 =
SUMX (
    VALUES ( Split2[Product] ),
    SUMX (
        FILTER (
            SUMMARIZECOLUMNS (
                Split[Sales Order],
                Split[Count],
                "@filter", [FilteredProduct]
            ),
            [@filter]
        ),
        [Count]
    )
)

Outer SUMX:

Iterates over each unique value in Split2[Product].

Inner SUMX:

Processes a filtered table created by:

  • SUMMARIZECOLUMNS:
    • Groups data from the Split table by Sales Order and Count.
      Adds a calculated column @filter, which evaluates the FilteredProduct measure for each group.
  • FILTER:
    • Keeps only the rows where @filter is TRUE (i.e., the conditions in FilteredProduct are met).

The result of the inner SUMX is evaluated for each row in VALUES ( Split2[Product] ) in the outer SUMX and then summed up.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

11 REPLIES 11
danextian
Super User
Super User

Hi @Asingh31 

This was a tricky one. I had to spliteach product in the list into its own individual row. Then, I duplicated that table and created up three new measures to work with it.

danextian_0-1737035736600.png

 

danextian_1-1737035835386.png

Please see the attached pbix.

FilteredProduct = 
VAR productcount =
    COUNTROWS ( Split2 )
RETURN
    productcount
        <= CALCULATE (
            COUNTROWS ( Split ),
            KEEPFILTERS (
                Split[Individual Products] IN VALUES ( Split2[Individual Products] )
            )
        )

Count in Split1 = 
SUMX (
    FILTER (
        SUMMARIZECOLUMNS (
            Split[Sales Order],
            Split[Count],
            "@filter", [FilteredProduct]
        ),
        [@filter]
    ),
    [Count]
)

Total in Split2 =
SUMX (
    VALUES ( Split2[Product] ),
    SUMX (
        FILTER (
            SUMMARIZECOLUMNS (
                Split[Sales Order],
                Split[Count],
                "@filter", [FilteredProduct]
            ),
            [@filter]
        ),
        [Count]
    )
)


 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hi @danextian , wow amazing. I'll go through the solution and if I don't understand something will write you back.

Thank you for the solution.

Cheers 

FilteredProduct = 
VAR productcount =
    COUNTROWS ( Split2 )
RETURN
    productcount
        <= CALCULATE (
            COUNTROWS ( Split ),
            KEEPFILTERS (
                Split[Individual Products] IN VALUES ( Split2[Individual Products] )
            )
        )

VAR productcount:

Counts the number of rows in the Split2 table within the current filter context., ie based on the slicer selection from Split2

 

RETURN Statement:

Compares productcount with the result of the CALCULATE function:

  • COUNTROWS(Split): Counts the rows in the Split table.
    KEEPFILTERS with IN VALUES: Ensures that the filter from Split2[Individual Products] is applied to
  • Split[Individual Products], so only rows with matching products are considered.
    The measure returns TRUE if the row count in Split2 (productcount) is less than or equal to the filtered row count in Split. Otherwise, it returns FALSE.
Total in Split2 =
SUMX (
    VALUES ( Split2[Product] ),
    SUMX (
        FILTER (
            SUMMARIZECOLUMNS (
                Split[Sales Order],
                Split[Count],
                "@filter", [FilteredProduct]
            ),
            [@filter]
        ),
        [Count]
    )
)

Outer SUMX:

Iterates over each unique value in Split2[Product].

Inner SUMX:

Processes a filtered table created by:

  • SUMMARIZECOLUMNS:
    • Groups data from the Split table by Sales Order and Count.
      Adds a calculated column @filter, which evaluates the FilteredProduct measure for each group.
  • FILTER:
    • Keeps only the rows where @filter is TRUE (i.e., the conditions in FilteredProduct are met).

The result of the inner SUMX is evaluated for each row in VALUES ( Split2[Product] ) in the outer SUMX and then summed up.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hi @danextian , Thank you for the detailed explanation. Appreciate it.

Best,
AS

bhanu_gautam
Super User
Super User

@Asingh31 , Try using

 

dax
Total Count for Combinations =
SUMX(
'Table',
VAR CurrentRowProducts = 'Table'[Product]
RETURN
SUMX(
FILTER(
'Table',
CONTAINSSTRING(CurrentRowProducts, 'Table'[Product])
),
'Table'[Count]
)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Hi @bhanu_gautam ,

Thank you for your response but I am not getting desired result.

Asingh31_0-1737032906738.png

 

danextian
Super User
Super User

Hi @Asingh31 

 

The question is how do we know that the count pertains to a specific product in product column when there are multiple products in there? I'm guessing Product 4 = 3, Product 3 = 5 and Product 2 = 10 for the first 3 rows. But rows 4 and 5 dont follow the aformentioned logic.  Always provide a workable sample data (not an image), the expected result and a concrete reasoning behind.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hi,
These products combinations are single orders. SO each row is an order where some one ordered 2 products or more. Now I have to calculate how many times these combinations are ordered. 
So in my example:
Product 1 and Product 2 (only these 2 ) are ordered 10 times. But in second row and 3rd row Product 1 and Product 2 is also there and being ordered. So I want the sum of these 3 rows for Product 1 and Product 2 combination.
Hope it expalins.
Thank you.

bhanu_gautam
Super User
Super User

@Asingh31 , Can you share sample data




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






done

amitchandak
Super User
Super User

@Asingh31 , You can use Visual calculation of Window function for that

 

Visual calculation is running sum

Master Visual Calculations in Power BI- February 2024 Update RUNNINGSUM, RANGE, MOVINGAVERAGE, COLLAPSE, COLLAPSEALL, EXPAND, EXPANDALL, FIRST, LAST, PREVIOUS, and NEXT
https://www.youtube.com/watch?v=bKD9T0EWgQo&list=PLPaNVDMhUXGYo50Ajmr4SgSV9HIQLxc8L

 

 

In Window function you have to use order by product

Power BI Window function Rolling, Cumulative/Running Total, WTD, MTD, QTD, YTD, FYTD: https://youtu.be/nxc_IWl-tTc

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors