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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Concatenate rows values based on DAX MEASURE value

I am trying to concatenate the [Step] column and also sum the [Quantity] column if the cumulative total is < required balance AND also the first instance where the cumulative total is >= required balance


What I am trying to do is to find out for each specific product, are the ones which has progressed the furthest (highest [Step]) along the chain, and seek them out to meet my [Required balance].

The pain comes because [Product], [Step], [Quantity], [Required balance] is part of an actual column, while [Cumulative total] and [Cumulative total < Required balance] is a calculated measure. 

2 tables are involved here:
Required balance: [Product], [Required balance]
Quantity: [Product], [Step], [Quantity]

'Required balance'[Product] is linked to 'Quantity'[Product] in a one-to-many relationship.

 

ProductStepQuantityRequired balanceCumulative totalCumulative total < Required balance
A10127512True
A9717583False
A8127595False
A74875143False


Ideally my output should be:

ProductSteps requiredCumulative total
A10, 983



@Greg_Deckler @amitchandak 

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @Anonymous 

 

Create the following measures:

 

Quantity Value = sum(Quantity[Quantity])

Steps Below =
VAR QuantityCumulative =
    ADDCOLUMNS (
        ALLSELECTED ( Quantity[Step] ),
        "@Quantity", [Quantity Value],
        "@CumulativeQuantity", [CUMULATIVE TOTAL]
    )
VAR QuantityBelowRequired =
    COUNTROWS (
        FILTER (
            QuantityCumulative,
            [@CumulativeQuantity] < SUM ( 'Required Balance'[Required balance] )
        )
    ) + 1
RETURN
    CONCATENATEX (
        TOPN ( QuantityBelowRequired, QuantityCumulative, [@CumulativeQuantity], ASC ),
        Quantity[Step],
        ",",
        Quantity[Step], DESC
    )


Cumulative value = 
VAR QuantityCumulative =
    ADDCOLUMNS (
        ALLSELECTED ( Quantity[Step] ),
        "@Quantity", [Quantity Value],
        "@CumulativeQuantity", [CUMULATIVE TOTAL]
    )
VAR QuantityBelowRequired =
    COUNTROWS (
        FILTER (
            QuantityCumulative,
            [@CumulativeQuantity] < SUM ( 'Required Balance'[Required balance] )
        )
    ) + 1
RETURN
    MAXX (
        TOPN ( QuantityBelowRequired, QuantityCumulative, [@CumulativeQuantity], ASC ),
        [@CumulativeQuantity]
    )

 

Final result below and in attach PBIX file.

MFelix_0-1659001078954.png

 

 

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

2 REPLIES 2
MFelix
Super User
Super User

Hi @Anonymous 

 

Create the following measures:

 

Quantity Value = sum(Quantity[Quantity])

Steps Below =
VAR QuantityCumulative =
    ADDCOLUMNS (
        ALLSELECTED ( Quantity[Step] ),
        "@Quantity", [Quantity Value],
        "@CumulativeQuantity", [CUMULATIVE TOTAL]
    )
VAR QuantityBelowRequired =
    COUNTROWS (
        FILTER (
            QuantityCumulative,
            [@CumulativeQuantity] < SUM ( 'Required Balance'[Required balance] )
        )
    ) + 1
RETURN
    CONCATENATEX (
        TOPN ( QuantityBelowRequired, QuantityCumulative, [@CumulativeQuantity], ASC ),
        Quantity[Step],
        ",",
        Quantity[Step], DESC
    )


Cumulative value = 
VAR QuantityCumulative =
    ADDCOLUMNS (
        ALLSELECTED ( Quantity[Step] ),
        "@Quantity", [Quantity Value],
        "@CumulativeQuantity", [CUMULATIVE TOTAL]
    )
VAR QuantityBelowRequired =
    COUNTROWS (
        FILTER (
            QuantityCumulative,
            [@CumulativeQuantity] < SUM ( 'Required Balance'[Required balance] )
        )
    ) + 1
RETURN
    MAXX (
        TOPN ( QuantityBelowRequired, QuantityCumulative, [@CumulativeQuantity], ASC ),
        [@CumulativeQuantity]
    )

 

Final result below and in attach PBIX file.

MFelix_0-1659001078954.png

 

 

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

This is such a clean measure (as compared to the one I came up with), perfect thanks!

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.