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

How to calculate difference between two columns - related column and count column

I'm struggling with this.  I want to create a column that calculates the difference of (First RequiredShiftA) and (CountDuringShiftA) columns.

 

This started as two tables.  I created new columns in my larger table to add the related columns of the required roles, shift a, and shift b thinking that once they were in the same table it would be easy to just subtract one column from the other - nope.

 

 

 

powerbi.JPG

11 REPLIES 11
ibarrau
Super User
Super User

Hi. I think I might me missing something. Did you try creating a new calculated dax column on the big table with the following formula?

Table[Column1] - Table[Column2] 

Regards


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

Happy to help!

LaDataWeb Blog

Anonymous
Not applicable

For example, using that formula:

 

instead of 2 - 2 = 0 

I am getting -6

 

So I'm not exactly sure what is being calculated

Are you sure you are checking the result in the data view?

2 - 2 = 6  sounds like having the visualization with a value of SUM of calculatedColumn.

 

Can you show a picture with the two columns and the substract result from the DataView?

 


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

Happy to help!

LaDataWeb Blog

Anonymous
Not applicable

The one column was a quick measure and doesn't show up in the data view.pbi data view.JPG

Then don't use a "quick measure" and create a "calculated column" with the substract.

 


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

Happy to help!

LaDataWeb Blog

Anonymous
Not applicable

I've been trying.  I get a lot of errors.

 

pbi circular dep.JPG

Can you send a picture of the data model? I think if we have only three tables with single directional relation we shouldn't be seeing this error.


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

Happy to help!

LaDataWeb Blog

Anonymous
Not applicable

I think this is what i'm trying to do - but have no idea - this DAX stuff is crazy.

 

I basically want a count of all the during roles for shift b that gets subtracted from the # of required roles for shift b.  pbi error.JPG

 

CALCULATE(

    COUNTA('Contact Export PowerBI'[During Section and Role]),

    'Contact Export PowerBI'[During Shift] IN { "B Shift" } - 'Contact Export PowerBI'[RequiredShiftB])

I don't think I'm following the whole idea. Try to use variables to avoid this kind of error. The formula you are showing looks like a measure. I think this code should help:

VAR counting = COUNTA('Contact Export PowerBI'[During Section and Role]),

VAR in_shift_b = 
CALCULATE (
    countring , 
    'Contact Export PowerBI'[During Shift] = "B Shift" 
)
 VAR number_of_req_roles = COUNT('Contact Export PowerBI'[RequiredShiftB] )

RETURN
in_shift_b - number_of_req_roles

Hope this helps,

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


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

Happy to help!

LaDataWeb Blog

Are you sure you are checking the result in the data view?

2 - 2 = 6  sounds like having the visualization with a value of SUM of calculatedColumn.

 

Can you show a picture with the two columns and the substract result from the DataView?

 


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

Happy to help!

LaDataWeb Blog

Anonymous
Not applicable

I did try that but the results are no where near correct.  

 

 

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.

Top Solution Authors