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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Total of all minus total of non-blank

Dear Community, 

 

I would me very grateful if someone could give me a hint on how to solve the following problem:

 

I imported a table in PBI that looks something like this:

noraaziri_1-1635838018325.png

Column "EUR/T" indicates bonus per ton of goods sold, meaning that, where construction site is not blank - apply 1,5 eur/t bonus, and where it is blank - it means all the rest of the construction sites get 1 eur/t bonus.

How to create a DAX that would basically say, if construction site is blank, then take the total of all quantities sold per given customer and subtract from it the quantities of non-blank construction sites of the same customer?

 

I´d be extremely grateful if someone would take a look at this.

 

Thanks a lot!!

 

Nora

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

Hi @Anonymous ,

See the below:

Step ,import data:

vluwangmsft_0-1635994763534.png

Step 2,get Eur/t:

Eur/t = IF('Table'[Construction Site]=BLANK(),1,1.5)

vluwangmsft_1-1635994802752.png

 

 

Step 3, use the following measure then create visual:

test = 
CALCULATE (
    SUM ( 'Table'[Eur/t] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Customer_Nr] = MAX ( 'Table'[Customer_Nr] )
            && 'Table'[Construction Site] <> BLANK ()
    )
)
    - CALCULATE (
        SUM ( 'Table'[Eur/t] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Customer_Nr] = MAX ( 'Table'[Customer_Nr] )
                && 'Table'[Construction Site] = BLANK ()
        )
    )

vluwangmsft_2-1635994857952.png

Verification

214214:8*1.5-1 =11

214215:2*1.5-1=2

 

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


Best Regards

Lucien

View solution in original post

6 REPLIES 6
v-luwang-msft
Community Support
Community Support

Hi @Anonymous ,

See the below:

Step ,import data:

vluwangmsft_0-1635994763534.png

Step 2,get Eur/t:

Eur/t = IF('Table'[Construction Site]=BLANK(),1,1.5)

vluwangmsft_1-1635994802752.png

 

 

Step 3, use the following measure then create visual:

test = 
CALCULATE (
    SUM ( 'Table'[Eur/t] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Customer_Nr] = MAX ( 'Table'[Customer_Nr] )
            && 'Table'[Construction Site] <> BLANK ()
    )
)
    - CALCULATE (
        SUM ( 'Table'[Eur/t] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Customer_Nr] = MAX ( 'Table'[Customer_Nr] )
                && 'Table'[Construction Site] = BLANK ()
        )
    )

vluwangmsft_2-1635994857952.png

Verification

214214:8*1.5-1 =11

214215:2*1.5-1=2

 

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


Best Regards

Lucien

VahidDM
Super User
Super User

Hi @Anonymous 

Try this measure:

 

Measure = 
VAR _QTYB =
    CALCULATE (
        SUM ( 'Table'[quantities ] ),
        'Table'[construction site] = BLANK ()
    )
VAR _QTYNB =
    CALCULATE (
        SUM ( 'Table'[quantities ] ),
        'Table'[construction site] <> BLANK ()
    )
RETURN
    _QTYNB - _QTYB

 

Output:

 

VahidDM_0-1635839454032.png

 

 

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

Appreciate your Kudos!!

 

Anonymous
Not applicable

@VahidDM , 

 

The output I get is the following

noraaziri_0-1635842764957.png

 

The total should be 269,5 , and the "blank" should be (269,5-23)=246,5.

 

Any idea of how to arrive there? 🙂

 

Kind regards

Nora

Anonymous
Not applicable

Hi Vahid, 

 

Thanks a lot for your reply!!

I have tried the same measure logic, but it doesn´t work for me and here is why - I didn´t mention that the quantities come from another table (from SQL server), and the table I showed in the post only serves to identify customers and respective construction sites that have these bonuses according to contract.

Since I connected the two tables by construction site columns, it is obviously a bit of an issue how to treat blank column values.. I hope I managed to explain it right..

amitchandak
Super User
Super User

@Anonymous , a new column

column =


if(isblank([construction site]) , sumx(filter(Table, [customer] =earlier([customer]) && not(isblank([construction site]) )) ,[Eur/t]) -sumx(filter(Table, [customer] =earlier([customer]) && (isblank([construction site]) )) ,[Eur/t]) ,[Eur/t])

Anonymous
Not applicable

Hi!

 

Thanks for your reply! I am still trying to implement your suggestion, and will let you know how it went!

 

Nora

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.