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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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