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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Caculated column with Dax

Anis_Hussain_0-1680531406007.png

For this data set
I want to achieve for each StoreCode the Daily Sale is not blank and >0 for last 14 days then in Comparison column I want Yes else No.
Please help me writing this dax 

@freemanZ

2 REPLIES 2
tamerj1
Super User
Super User

Hi @Anonymous 

please try

Comparison =
VAR CurrentDate = Sales[Retail Dates]
VAR CurrentStoreTable =
CALCULATETABLE ( Sales, ALLEXCEPT ( Sales, Sales[StoreCode] ) )
VAR Last14Days =
FILTER (
CurrentStoreTable,
Sales[Retail Dates] <= CurrentDate
&& Sales[Retail Dates] > CurrentDate - 14
)
VAR Last14DaysWithValue =
FILTER ( Last14Days, Sales[Daily Sale] > 0 )
RETURN
IF ( COUNTROWS ( Last14DaysWithValue ) = COUNTROWS ( Last14Days ), "Yes", "No" )

Wilson_
Super User
Super User

 

Hello Anis,

 

I am not FreemanZ, but hopefully my solution below is acceptable too. 😉 Let me know if the below calculated column works for you or if it is not what you're looking for.

 

Comparison = 
VAR CurrentDate = Table1[Retail Date]
VAR FilteredSales =
FILTER (
    Table1,
    DATEDIFF ( Table1[Retail Date], CurrentDate, DAY ) < 14 &&
    DATEDIFF ( Table1[Retail Date], CurrentDate, DAY ) >= 0
)
VAR Last14DaysSales =
SUMX (
    FilteredSales,
    Table1[Daily Sales]
)

RETURN
SWITCH (
    TRUE(),
    NOT ( ISBLANK ( Table1[Daily Sales] ) ) && Last14DaysSales > 0, "Yes",
   "No"
)

 

----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.