Forum Discussion
Sales from different table dependant on the promo code
- Anonymous2 years ago
VahidDM Thanks for your contribution on this thread.
Hi amadnei ,
You can follow the steps below to get it, please find the details in the attachment.
1. Create the relationship between 'All sales' table and 'promotion code' table with the field 'All sales' [[ITEM_NAME]] and 'promotion code' [PROMO_ITEM_NAME]
2. Create a measure as below to get it:
SALE_FROM_CODE = VAR _itemname = SELECTEDVALUE ( 'All sales'[ITEM_NAME] ) RETURN CALCULATE ( SUM ( 'All sales'[SALES] ), FILTER ( 'All sales', 'All sales'[ITEM_NAME] = _itemname && 'All sales'[SALE_CODE] IN VALUES ( 'promotion code'[PROMO_CODE] ) ) )Best Regards
Hi amadnei
Can you post sample data as text with column names and expected output?
Little bit confused
please see this post regarding How to Get Your Question Answered Quickly:
https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
The most important parts are:
1. Sample data as text, use the table tool in the editing bar (Add Column names)
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.
4. Relation between your tables
Appreciate your Kudos!!
LinkedIn:www.linkedin.com/in/vahid-dm/
- amadnei2 years agoNew Member
Here is a mockup of my 2 main table, with the expected result
All sales tableITEM_ID ITEM_NAME SALE_CODE SALES 1 BLENDER CODE1 4 1 BLENDER CODE1 52 1 BLENDER CODE2 5 1 BLENDER CODE3 12 1 BLENDER CODE4 56 2 TABLE CODE1 9 2 TABLE CODE3 23 2 TABLE CODE4 52 3 KNIFE CODE1 12 3 KNIFE CODE2 25 3 KNIFE CODE3 63 3 KNIFE CODE3 12 3 KNIFE CODE4 7 promotion code
PROMO_ITEM_ID PROMO_ITEM_NAME PROMO_CODE 1 BLENDER CODE3 1 BLENDER CODE4 2 KNIFE CODE3 EXPECTED_RESULTITEM_NAME SALE_FROM_CODE BLENDER 68 KNIFE 75 Note that some code from the 2nd table are available on other item that are not in the promo table, but I can't count those in. It's because sometime promo code are used as regular code.
I guess the basic explaination is : IF code + item name are in 1st table, get those sales.
I tried a simple calculate(filter(all(table1) code = code & name = name, but doesn't work properly and take ages to load.
Also tried to use IN function, work very well for few code, but not sure how to add a switch function to change code dependant on the item name.
Hope it's clearer ! thanks 🙂- Anonymous2 years agoNot applicable
VahidDM Thanks for your contribution on this thread.
Hi amadnei ,
You can follow the steps below to get it, please find the details in the attachment.
1. Create the relationship between 'All sales' table and 'promotion code' table with the field 'All sales' [[ITEM_NAME]] and 'promotion code' [PROMO_ITEM_NAME]
2. Create a measure as below to get it:
SALE_FROM_CODE = VAR _itemname = SELECTEDVALUE ( 'All sales'[ITEM_NAME] ) RETURN CALCULATE ( SUM ( 'All sales'[SALES] ), FILTER ( 'All sales', 'All sales'[ITEM_NAME] = _itemname && 'All sales'[SALE_CODE] IN VALUES ( 'promotion code'[PROMO_CODE] ) ) )Best Regards