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
djworsdell
Frequent Visitor

Calculate value by matching only one of many multiple comma-seperated values

Hey all,

 

I have a large dataset with an ID and corresponding value, and want to SUM() those together using CALCULATE() and FILTER() to add them up together based on which item has what ID (or IDs). Each item might have one or more IDs which need to be matched in the data table.

 

Data

IDTotal
X-023330
X-023350
X-966080
X-966077
X-966063
X-9955185
X-775580
X-775596

 

Items

IDsTotals (what I need to calculate!)
X-023380
X-0233, X-9660300
X-7755, X-0233, X-9660380

 

I've tried with the following DAX, but it will only return an item total if there is only one ID, not multiple IDs separated by a comma.

 

totals = CALCULATE(
    SUM(data[id]),
    FILTER(
        VALUES(data),
        CONTAINSSTRING(data[id], items[ids])
    )
)

 

 

Previsouly I've used a measure and a relationship to complete this when there was only one ID to match with another ID - that was much easier!

 

Any suggestions or ideas would be incredible as I'm completely stuck on this one! Thanks all.

1 ACCEPTED SOLUTION
v-rongtiep-msft
Community Support
Community Support

Hi @djworsdell , 

Please refer to my pbix file to see if it helps you.

Create a measure.

Measure = 
SUMX (
    CALCULATETABLE (
        'Date',
        CONTAINSSTRING ( SELECTEDVALUE ( Items[Ds] ), 'Date'[ID] )
    ),
    [Total]
)

vpollymsft_0-1648191648847.png

 

If I have misunderstood your meaning, please provide your pbix file without privacy information and more details with your desired output.

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

2 REPLIES 2
v-rongtiep-msft
Community Support
Community Support

Hi @djworsdell , 

Please refer to my pbix file to see if it helps you.

Create a measure.

Measure = 
SUMX (
    CALCULATETABLE (
        'Date',
        CONTAINSSTRING ( SELECTEDVALUE ( Items[Ds] ), 'Date'[ID] )
    ),
    [Total]
)

vpollymsft_0-1648191648847.png

 

If I have misunderstood your meaning, please provide your pbix file without privacy information and more details with your desired output.

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

tamerj1
Super User
Super User

Hi @djworsdell 

You may try

 

 

totals =
VAR CurrentItemsID = Itms[ID's]
RETURN
    SUMX (
        FILTER ( Data, CONTAINSSTRING ( data[id], CurrentItemsID ) ),
        Data[Total]
    )

 

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors