cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Anonymous
Not applicable

Add the value from one article to other articles

I have a table with Articles that have a combination of two articles. I want to create a new Value Column where I add the value of those articles to the basic one.

Example: The value from article Vitamin C + Vitamin D needs to be added +20 on Vitamin C and +20 on Vitamin D. I'm not sure with is easier in dax or in query.

adriandumitru_0-1676899365301.png

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Anonymous 
Please refer to attached sample file with the proposed solution based on measure.

1.png

DAX Value = 
SUMX ( 
    VALUES ( 'Table'[Article] ),
    VAR CurrentArticle = 'Table'[Article]
    RETURN
        IF ( 
            CONTAINSSTRING ( CurrentArticle, "+" ),
            0,
            SUMX ( 
                FILTER ( 
                    ALL ( 'Table'[Article] ),
                    CONTAINSSTRING ( 'Table'[Article], CurrentArticle )
                ), 
                VAR ThisArticle = 'Table'[Article]
                RETURN
                    CALCULATE ( SUM ( 'Table'[Value] ) )
            )
        )
)

View solution in original post

7 REPLIES 7
tamerj1
Super User
Super User

Hi @Anonymous 
Please refer to attached sample file with the proposed solution based on measure.

1.png

DAX Value = 
SUMX ( 
    VALUES ( 'Table'[Article] ),
    VAR CurrentArticle = 'Table'[Article]
    RETURN
        IF ( 
            CONTAINSSTRING ( CurrentArticle, "+" ),
            0,
            SUMX ( 
                FILTER ( 
                    ALL ( 'Table'[Article] ),
                    CONTAINSSTRING ( 'Table'[Article], CurrentArticle )
                ), 
                VAR ThisArticle = 'Table'[Article]
                RETURN
                    CALCULATE ( SUM ( 'Table'[Value] ) )
            )
        )
)
Anonymous
Not applicable

Thank you, @tamerj1 

Can you explain the logic behind it? How it knows that an Article that contains + needs to go on the corelated Article and not another? 

@Anonymous 
It doesn't have to do that. It just need to check whether the current row Article name is part of the name of the article under the iteration inside FILTER.

The code is pretty simple, just concentrate on the inner SUMX:

SUMX (
    FILTER (
        ALL ( 'Table'[Article] ),
        CONTAINSSTRING ( 'Table'[Article], CurrentArticle )
    ),
    CALCULATE ( SUM ( 'Table'[Value] ) )
)

This is a simple SUMX over a filter of all articles that conatin the name of the current article.

The if statement is just to return zoro in case "+" is partr of the name (a combined name)

IF (
    CONTAINSSTRING ( CurrentArticle, "+" ),
    0,
    SUMX (
        FILTER (
            ALL ( 'Table'[Article] ),
            CONTAINSSTRING ( 'Table'[Article], CurrentArticle )
        ),
        CALCULATE ( SUM ( 'Table'[Value] ) )
    )
)

And finally the outer SUMX is just to provide correct values at total level

DAX Value =
SUMX (
    VALUES ( 'Table'[Article] ),
    VAR CurrentArticle = 'Table'[Article]
    RETURN
        IF (
            CONTAINSSTRING ( CurrentArticle, "+" ),
            0,
            SUMX (
                FILTER (
                    ALL ( 'Table'[Article] ),
                    CONTAINSSTRING ( 'Table'[Article], CurrentArticle )
                ),
                CALCULATE ( SUM ( 'Table'[Value] ) )
            )
        )
)
Anonymous
Not applicable

Thank you!

That was a sample made by my because I thought it is more difficult.

For this kind of articles do you think there is a soulution?

On the left are the base article and on the right are the combined articles.

Cod BaseName BaseCod PackName Pack
12892Alive! Men’s 50+ Ultra 30 tab filmateP12892Alive! Men’s 50+ + Alive! Women’s 50+ Ultra 30tab 
12893Alive! Women’s 50+ Ultra 30 tab filmateP12892Alive! Men’s 50+ + Alive! Women’s 50+ Ultra 30tab 
12894Alive! Men’s Ultra 30 tab filmateP12894Alive! Men’s +Women`s Ultra 30 tab filmate
12895Alive! Women’s Ultra 30 tab filmateP12894Alive! Men’s +Women`s Ultra 30 tab filmate
11852Vitamin D3 2000UI (adulti) 30 caps moiP31501Vitamin C adulti + Vitamin D3 adulti 30cps
31501Vitamin C 1000mg (adulti) 30 caps vegP31501Vitamin C adulti + Vitamin D3 adulti 30cps
47239L-Arginine 1000mg 30 tab RapidSolvPP47239L-Arginine 1000mg 30 tab+Guard-Your-Liver 30 caps
200005Guard-Your-LiverPP47239L-Arginine 1000mg 30 tab+Guard-Your-Liver 30 caps
862MSM 750mg 90 caps vegPP862MSM 750mg + Vitamin D3 30cps GRATIS
11852Vitamin D3 30cpsPP862MSM 750mg + Vitamin D3 30cps GRATIS
CL10150First DefensePPCL10150First Defense + Vitamina C copii 
CL10200Vitamin C 250mg (copii) 118mlPPCL10150First Defense + Vitamina C copii 
CL10200Vitamin C 250mg (copii) 118mlPPCL10200Vitamin C adulti 30cps + Vitamin C copii 250mg
31501Vitamin C 1000mg (adulti) 30 caps vegPPCL10200Vitamin C adulti 30cps + Vitamin C copii 250mg
CL10900Vitamin D3 500UI (copii) 30mlPPCL10900Vitamin D3 adulti 30cps + Vitamin D3 copii 30ml
11852Vitamin D3 2000UI (adulti) 30 caps moiPPCL10900Vitamin D3 adulti 30cps + Vitamin D3 copii 30ml
862MSM 750mg 90 caps vegPR862MSM 750mg + Vitamin D3 30cps 
11852Vitamin D3 30cpsPR862MSM 750mg + Vitamin D3 30cps 
CL10150First Defense 118.50ml PRPCL10150First Defense 118.50ml + Toothpaste Tablets 60 tablete (gust de fructe) gratuit
CL10200Vitamin C 250mg (copii) 118mlPRPCL10200Kit imunitate copii (Vitamin C+ D3)
CL10900Vitamin D3 500UI (copii) 30mlPRPCL10200Kit imunitate copii (Vitamin C+ D3)

@Anonymous 
Where is the value and what is the expected result based on this sample data?

Anonymous
Not applicable

sorry, this is

Cod BaseName BaseCod PackName PackValueExpected Result
12892Alive! Men’s 50+ Ultra 30 tab filmateP12892Alive! Men’s 50+ + Alive! Women’s 50+ Ultra 30tab 4040
12893Alive! Women’s 50+ Ultra 30 tab filmateP12892Alive! Men’s 50+ + Alive! Women’s 50+ Ultra 30tab  40
12894Alive! Men’s Ultra 30 tab filmateP12894Alive! Men’s +Women`s Ultra 30 tab filmate4040
12895Alive! Women’s Ultra 30 tab filmateP12894Alive! Men’s +Women`s Ultra 30 tab filmate 40
11852Vitamin D3 2000UI (adulti) 30 caps moiP31501Vitamin C adulti + Vitamin D3 adulti 30cps4040
31501Vitamin C 1000mg (adulti) 30 caps vegP31501Vitamin C adulti + Vitamin D3 adulti 30cps 40
47239L-Arginine 1000mg 30 tab RapidSolvPP47239L-Arginine 1000mg 30 tab+Guard-Your-Liver 30 caps4040
200005Guard-Your-LiverPP47239L-Arginine 1000mg 30 tab+Guard-Your-Liver 30 caps 40
862MSM 750mg 90 caps vegPP862MSM 750mg + Vitamin D3 30cps GRATIS4040
11852Vitamin D3 30cpsPP862MSM 750mg + Vitamin D3 30cps GRATIS 40
CL10150First DefensePPCL10150First Defense + Vitamina C copii 4040
CL10200Vitamin C 250mg (copii) 118mlPPCL10150First Defense + Vitamina C copii  40
CL10200Vitamin C 250mg (copii) 118mlPPCL10200Vitamin C adulti 30cps + Vitamin C copii 250mg4040
31501Vitamin C 1000mg (adulti) 30 caps vegPPCL10200Vitamin C adulti 30cps + Vitamin C copii 250mg 40
CL10900Vitamin D3 500UI (copii) 30mlPPCL10900Vitamin D3 adulti 30cps + Vitamin D3 copii 30ml4040
11852Vitamin D3 2000UI (adulti) 30 caps moiPPCL10900Vitamin D3 adulti 30cps + Vitamin D3 copii 30ml 40
862MSM 750mg 90 caps vegPR862MSM 750mg + Vitamin D3 30cps 4040
11852Vitamin D3 30cpsPR862MSM 750mg + Vitamin D3 30cps  40
CL10200Vitamin C 250mg (copii) 118mlPRPCL10200Kit imunitate copii (Vitamin C+ D3)4040
CL10900Vitamin D3 500UI (copii) 30mlPRPCL10200Kit imunitate copii (Vitamin C+ D3) 40

@Anonymous 

Again I don't think this reflects the real problem. If this really represents the real case then the solution is simply 

Expected Result (Cslculated Colunn) =
CALCULATE (

SUM ( 'Table'[Value] ),

ALLEXCEPT ( 'Table', 'Table'[Cod Pack] )

)

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

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

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors