Forum Discussion
hassanh2
Helper I
4 years agoDAX Function / Query to create a flag for products
Hello, Can anyone help with the following: I have 2 tables (Item Master and Sales) and want to create a column/measure in the sales table to flag the products according to the following logic: ...
- 4 years ago
Step1
Latest Order Year = CALCULATE(MAX(Sales[Year]),ALLEXCEPT(Sales,Sales[Product Name]))Step2Count of Orders = CALCULATE(DISTINCTCOUNT(Sales[Year]),ALLEXCEPT(Sales,Sales[Product Name]),Sales[Year]>=year(TODAY())-1)Switch Flag = SWITCH( TRUE(), [Count of Orders]=1&&[Latest Order Year]=year(TODAY()),"New" ,[Count of Orders]=1,"No",[Count of Orders]>1&&[Latest Order Year]=year(TODAY()),"Existing")OR
Using Variable,
Switch Flag Parameter = var Latest_Order_Year = CALCULATE(MAX(Sales[Year]),ALLEXCEPT(Sales,Sales[Product Name]))var Count_of_Orders = CALCULATE(DISTINCTCOUNT(Sales[Year]),ALLEXCEPT(Sales,Sales[Product Name]),Sales[Year]>=year(TODAY())-1)return SWITCH( TRUE(), [Count of Orders]=1&&[Latest Order Year]=year(TODAY()),"New" ,[Count of Orders]=1,"No",[Count of Orders]>1&&[Latest Order Year]=year(TODAY()),"Existing")Regards,
Ritesh
ribisht17
Super User
4 years agoThat is Nokia which was there in the last year as well(2nd row),so it should be existing ,right ?
ribisht17
Super User
4 years agoMark my post as a solution if it helped you| Munde and Kudis (Ladies and Gentlemen) I like your Kudos!! !!
My YT Channel Dancing With Data !! Connect on Linkedin !!Power BI for Tableau Users
My YT Channel Dancing With Data !! Connect on Linkedin !!Power BI for Tableau Users