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

Switch True, getting a value which is not included in total

Hi

 

I am working with a orders dataset, and a order_lines dataset. I have created a measure which is called "Switch True":

Switch True = SWITCH( TRUE(),
[Is_B2B] = "B2B", [Order_Lines Quantity],
[Is_B2B] = "D2C", COUNT(Shopify_Orders[Order_Id]),
CALCULATE(COUNT(Shopify_Orders[Order_Id]), Shopify_Orders[Is B2B] = "D2C") + CALCULATE([Order_Lines Quantity],Shopify_Order_Line_Items[Is B2B] = "B2B"))
 
Is_B2B tells whether teh order is a B2B order or D2C order, and takes values from the column with the same name:
Is_B2B = SELECTEDVALUE(Shopify_Orders[Is B2B])
 
Order_line_item_quantity is just a sum of the quantity in the order_lines table:
Order_Lines Quantity = SUM(Shopify_Order_Line_Items[Order_Line_Items_Quantity])
 
I want to make is so that if "B2B" is chosen in the filter, it shows the sum of order_lines quantity, which it does
When "D2C" is selecte, show the count of order_id, which it does
 
lastly, if none is selected, show the count of order_id where the order is "D2C" + the order_lines_quantity where the order is a "B2B" order. The numbers are correct, but the problem arises when I want to sort it between orders which has a MMG4 product and orders which has not. No matter if I choose B2B, D2C or both, the 218 orders which does not have  a MMG4 product shows. These should not show when B2B is selected. Below is the code and pictures:
Does anyone have an idea of why those 218 orders are showing, even though I choose B2B in the filter?
The numbers in the switch true column in the visual are correct, even the total of 352 orders in B2B is correct. But it still shows the 218 D2C orders without MMG4.
 
 
HAS_MMG4 = If(Shopify_Orders[TOTAL_PRICE_NOK]<0,"Orders with MMG4",IF(CALCULATE(sum(Shopify_Order_Line_Items[HAS_MMG4]))>0,"Orders with MMG4","Orders without MMG4"))
Haroon950_0-1667844918824.pngHaroon950_0-1667845007403.pngHaroon950_1-1667845034304.png

 

 

 
 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi

I found the mistake

It was the Switch(TRUE()) which was incorrect :
The original measure:

Switch True = SWITCHTRUE(),
[Is_B2B] = "B2B"[Order_Lines Quantity],
[Is_B2B] = "D2C"COUNT(Shopify_Orders[Order_Id]),
CALCULATE(COUNT(Shopify_Orders[Order_Id]), Shopify_Orders[Is B2B] = "D2C") + CALCULATE([Order_Lines Quantity],Shopify_Order_Line_Items[Is B2B] = "B2B"))
 
In the else statement it says Shopify_Orders[Is B2B] = "D2C". It should have been 
Shopify_Order_Line_Items[Is B2B] = "D2C".
 
When I changed this, the D2C orders did not show when B2C was selected

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Hi

I found the mistake

It was the Switch(TRUE()) which was incorrect :
The original measure:

Switch True = SWITCHTRUE(),
[Is_B2B] = "B2B"[Order_Lines Quantity],
[Is_B2B] = "D2C"COUNT(Shopify_Orders[Order_Id]),
CALCULATE(COUNT(Shopify_Orders[Order_Id]), Shopify_Orders[Is B2B] = "D2C") + CALCULATE([Order_Lines Quantity],Shopify_Order_Line_Items[Is B2B] = "B2B"))
 
In the else statement it says Shopify_Orders[Is B2B] = "D2C". It should have been 
Shopify_Order_Line_Items[Is B2B] = "D2C".
 
When I changed this, the D2C orders did not show when B2C was selected
Stachu
Community Champion
Community Champion

can you share a screenshot of how [Is_B2B] evaluates when only B2B is selected vs when all are selected?



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Anonymous
Not applicable

Haroon950_0-1667846093028.png

Hi

 

As you can see, I did not but anything explicitly for what it should do when all are selected. I tried, but it did not work, so I just left it empty

Anonymous
Not applicable

Important fact:

The filter that is used is "Is B2B" from the order table, not the measure "is B2B" which I sent a screenshot of

Stachu
Community Champion
Community Champion

and [Is_B2B] returns "B2B" when B2B is selected in the slicer? not BLANK?



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Anonymous
Not applicable

Yes, that is correct.

When B2B filter is selected (from the orders table), the measure (shown in the table) shows B2B

Haroon950_0-1667846508964.png

 

Stachu
Community Champion
Community Champion

it evaluates to BLANK for "Orders without MMG4", which explains why it goes to the else condition of the SWITCH. SO most likely in Shopify_Orders there are no rows that have both "B2B" and "Orders without MMG4"
If you create this as a dimension table with join with existing column (and put the new one in the slicer), then I think i t should work fine, something like this

IsB2B
B2B
D2C


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Anonymous
Not applicable

Hi

I creatde the dimension table and used that as a slicer. Still the same result. Any other suggestions?
I have tried to alter the Has_MMG4 measure as well, but no luck yet

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.