Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

Reply
amadnei
New Member

Sales from different table dependant on the promo code

Hi guys, 
I am unsure how to proceed DAX wise with my current small project, I'll try to keep it short : 

I have a main sales table (t1) with all the sales, with all the generic codes
I have a second table that take thoses sale, with wich I have selected code,
And a final table that take some items that have special code on some occasion.

t1 : 

Item 1Code13
item 1Code25
item 1Code31
Item 2Code18
item 2Code25
item 2Code318
   

t3. 

item1Code4Sales from t1
   
   

 

Things is that the codes from T3 are dependant on the promotion, so item1 might get code4, where as item2 get code5.
Hence why I think making a table (t3) to have the item with the related promo code. The sales are still in t1, but I need to target them item by item for the additionnal code. (hope it make sense )

Any suggestion for a dax measure to get all sales from t1 generic code, + with the promo code ( from t3)

1 ACCEPTED SOLUTION
Anonymous
Not 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] )
        )
    )

vyiruanmsft_0-1713951503149.png

Best Regards

View solution in original post

5 REPLIES 5
amadnei
New Member

Hi, I can't post any work related data but I will make a small fake sheet to explain it better in the coming days if it help other understand.

That would be great!

VahidDM
Super User
Super User

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/

Here is a mockup of my 2 main table, with the expected result

All sales table

ITEM_IDITEM_NAMESALE_CODESALES
1BLENDERCODE14
1BLENDERCODE152
1BLENDERCODE25
1BLENDERCODE312
1BLENDERCODE456
2TABLECODE19
2TABLECODE323
2TABLECODE452
3KNIFECODE112
3KNIFECODE225
3KNIFECODE363
3KNIFECODE312
3KNIFECODE47

 

promotion code

PROMO_ITEM_IDPROMO_ITEM_NAMEPROMO_CODE
1BLENDERCODE3
1BLENDERCODE4
2KNIFECODE3

 

EXPECTED_RESULT
 
ITEM_NAMESALE_FROM_CODE
BLENDER68
KNIFE75

 

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 🙂

Anonymous
Not 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] )
        )
    )

vyiruanmsft_0-1713951503149.png

Best Regards

Helpful resources

Announcements
May PBI 25 Carousel

Power BI Monthly Update - May 2025

Check out the May 2025 Power BI update to learn about new features.

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

May 2025 Monthly Update

Fabric Community Update - May 2025

Find out what's new and trending in the Fabric community.