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
Aj24
Helper I
Helper I

help summing two categories in a variable with corresponding values

Hi Friends!

 

Just a quick question for summing two values.

My goal is: to create total cost value.

 

usually to create a new column we use: 

column = table[variable] + table[variable]

 

but this gets slightly tricky with my data. 

 

Current data is like this:

table called 'costs' and below are some variables in the table:

datetypevalueuniqueID
1/5/2020expenditure$101
1/7/2020forecast$201
1/6/2020expenditure$502
1/8/2020forecast$202
1/4/2020expenditure$201

 

so I want to create a new measure called total cost where each value which is expenditure is summed with each value that is a forecast for its relevant corresponding uniqueID.

 

so far I have: 

total cost = costs[type] = "expenditure" + cost[type] = "forecast"

but I don't know where each corresponding of the values comes in to be summed together... any help much appreciated!!

 

thanks in advance for all the shared tips and advice!! 

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

Hi, @Aj24 

According to your description and sample data, I think you can try this measure to achieve your requirement:

total cost =

CALCULATE(

    SUM('costs'[value]),

    FILTER(ALLSELECTED('costs'),

    [type] in {"expenditure","forecast"}&&

    [UniqueID]=MAX([UniqueID])))

Then create a table chart and place the column and measure like this:

v-robertq-msft_0-1617952958190.png

 

And you can get what you want.

You can download my test pbix file below

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

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

3 REPLIES 3
v-robertq-msft
Community Support
Community Support

Hi, @Aj24 

According to your description and sample data, I think you can try this measure to achieve your requirement:

total cost =

CALCULATE(

    SUM('costs'[value]),

    FILTER(ALLSELECTED('costs'),

    [type] in {"expenditure","forecast"}&&

    [UniqueID]=MAX([UniqueID])))

Then create a table chart and place the column and measure like this:

v-robertq-msft_0-1617952958190.png

 

And you can get what you want.

You can download my test pbix file below

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

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

amitchandak
Super User
Super User

@Aj24 , Create a new column like

 

sumx(filter(Table, [type] =earlier([type])), [value])

Thanks so much for your guidance @amitchandak !! 

I wrote it as: 

sumx(filter(Costs, Expenditure =earlier(Forecast)), Value) but unfortunately it didn't work 😞 

The error appeared saying 'the syntax for ')' is incorrect 

 

Really appreciate your time and help!! 

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.