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

New Column that is the division of one value over another, based on the value of another column

Hi All, 

 

I'm new to PowerBI and this forum. I apologise if this has been covered in a previous question: I hope it hasn't, or that this brings something useful to the community.

 

The data I have is as below, minus the column (variable) 'healthpertotal'.

It shows the amount of government spending (column 'value') on health, and its total spending aka expenditure (both in column 'function'), and its associated year of that spending (column 'year).

 

I want to make a new column that shows the percent of government health spending over its total spending, for a given year, as shown below in the column 'healthpertotal'

 

So for instance, in 1995, the value of this variable is (42587(health spending amount)/326420(total spending amount))*100=13.05.

As for the rows showing total spending, the 'healthpertotal' could be 'missing', 1 or 'not applicable' and the like. I am ok with any of these options.

 

How would I set up this new column 'healthpertotal'?

 

Thanks for your time and kind consideration.

functionyearvaluehealthpertotal
Health19954258713.05
Health19964420913.25
Health19974447213.07
Total1995326420 
Total1996333637 
Total1997340252 
1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Picture1.png

 

Health per Total CC =
SWITCH (
TRUE (),
Data[function] = "Total", BLANK (),
VAR currentyear = Data[year]
RETURN
DIVIDE (
CALCULATE (
MAX ( Data[value] ),
FILTER ( data, Data[function] = "Health" && Data[year] = currentyear )
),
CALCULATE (
MAX ( Data[value] ),
FILTER ( Data, Data[function] = "Total" && Data[year] = currentyear )
)
)
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Picture1.png

 

Health per Total CC =
SWITCH (
TRUE (),
Data[function] = "Total", BLANK (),
VAR currentyear = Data[year]
RETURN
DIVIDE (
CALCULATE (
MAX ( Data[value] ),
FILTER ( data, Data[function] = "Health" && Data[year] = currentyear )
),
CALCULATE (
MAX ( Data[value] ),
FILTER ( Data, Data[function] = "Total" && Data[year] = currentyear )
)
)
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Anonymous
Not applicable

Hi, I accepted the answer earlier as I'm sure that it would work. Now I'm back at my desktop and testing this code, it return the error: "A single value for column 'Function' in table 'data1' cannot be determined". It goes on to say "This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result."

I'm not sure what has caused this. The column 'function' only has the values 'Health' and 'Total'.

Hope you could still help.

 

Thanks

Hi,

May I ask to share your sample pbix file?

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


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.