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
micro20
New Member

Using SWITCH command to show a measure based on the row name of a table

Hi All,

 

I need to create a custom measure for a P&L format that shows the value based on the row name of a matrix table. The data is as follows;

 

micro20_0-1619111212409.pngmicro20_1-1619111248701.png

 

The requirement is to calculate the Gross Profit using a measure (i.e. Rev - COS) that will show as 60 in front of the GP (Gross Profit) line as shown below.

micro20_2-1619111324789.png

 

The following measures were created accordingly.

micro20_3-1619111372997.png

 

 

micro20_6-1619111462673.png

 

After doing some research I have used the SWITCH command to show the result. When the variable for the value to be used when the CurrentItem = Gross Profit is entered manually, the value is shown accordingly in the table as follows;

micro20_10-1619111901098.png

 

However, the problem appears when you assign the already created measure (i.e. Gross Profit) where the row dissapears from the table and no value is shown.

micro20_9-1619111642138.png

 

Appreciate the assistance on the DAX command in resolving the issue.

Thanks

1 ACCEPTED SOLUTION

Hi, @micro20 

 

Thank you for your feedback.

You can remove the filter inside the measure.

Please try the below, and check the sample pbix file that has a relationship between two tables.

 

Reporting Value =
VAR currentitem =
SELECTEDVALUE ( Line[Line Short Code] )
RETURN
SWITCH (
TRUE (),
currentitem = "GP", CALCULATE([Gross Profit], ALL(Line)),
CALCULATE ( [Actual], FILTER ( Actual, Actual[Line Short Code] = currentitem ) )
)
 
 

Hi, My name is Jihwan Kim.


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


Linkedin: https://www.linkedin.com/in/jihwankim1975/

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

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi, @micro20 

Please check the below picture and the sample pbix file's link down below.

I wrote exactly the same measures as yours.

I think you have automatically created a relationship between two tables.

if you disconnect it, I think you can have the result that you want.

 

 

 

Picture2.png

 

https://www.dropbox.com/s/fseim1se3j50fq5/micro20.pbix?dl=0 

 

 

Hi, My name is Jihwan Kim.

 

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

 

Linkedin: https://www.linkedin.com/in/jihwankim1975/

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


Hi Jihwan Kim.

 

Thank you for the solution. Yes when the relationship is removed the result needed appears.

 

However, does that mean we cannot have any relationships linking the tables to each other? Is there a work around where the relationship is intact and desired result is still achieved?

 

Appreciate the effort.

Hi, @micro20 

 

Thank you for your feedback.

You can remove the filter inside the measure.

Please try the below, and check the sample pbix file that has a relationship between two tables.

 

Reporting Value =
VAR currentitem =
SELECTEDVALUE ( Line[Line Short Code] )
RETURN
SWITCH (
TRUE (),
currentitem = "GP", CALCULATE([Gross Profit], ALL(Line)),
CALCULATE ( [Actual], FILTER ( Actual, Actual[Line Short Code] = currentitem ) )
)
 
 

Hi, My name is Jihwan Kim.


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


Linkedin: https://www.linkedin.com/in/jihwankim1975/

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


Hi Jihwan Kim,

 

Accept the above as the solution and well explained.

 

Thank you for the effort which is very much appreciated.

 

Best Regards

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.