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
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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.