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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Jansco
Helper I
Helper I

Count consecutive positives and negatives

I have measures (not columns) that total sales for the last 7 days, the 7 days before that, the 7 days before that (3 weeks prior) and the 7 days before that (4 weeks prior).

I need a count of whether weekly consecutive sales were up or down (total num weeks up and total Num weeks down will be measures in my table visual).

Also, this data is by customer in my table visual.
3 REPLIES 3
v-shex-msft
Community Support
Community Support

Hi @Jansco ,

You can consider to use 'weeknum' and 'year' as group to summary your records, then you can compare the difference between current week and previous week.

Diff =
VAR currDate =
    MAX ( Calendar[Date] )
VAR prevDate =
    DATE ( YEAR ( currDate ), MONTH ( currDate ), DAY ( curDate ) - 7 )
VAR curWeek =
    CALCULATE (
        SUM ( Table[Sales] ),
        FILTER (
            ALLSELECTED ( Table ),
            YEAR ( [Date] ) = YEAR ( currDate )
                && WEEKNUM ( [Date], 1 ) = WEEKNUM ( currDate, 1 )
        )
    )
VAR preWeek =
    CALCULATE (
        SUM ( Table[Sales] ),
        FILTER (
            ALLSELECTED ( Table ),
            YEAR ( [Date] ) = YEAR ( prevDate )
                && WEEKNUM ( [Date], 1 ) = WEEKNUM ( prevDate, 1 )
        )
    )
RETURN
    curWeek - preWeek

If above no help, please provide some sample data and expected result for test.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

My measures are set up like this:

SalesLast7 =calculate(sum(‘SalesTable’[Sales]),
(Datesinperiod(date[date], selevtedvslue (date[date])-1,-7,day)

SalesTwoWeeksPrior =
=calculate(sum(‘SalesTable’[Sales]),
(Datesinperiod(date[date], selevtedvslue (date[date])-8,-7,day)

I discovered a formula like the one below will work, but it takes FOREVER. Is there a faster way?

 

Num Consec Ups 60 Days =

 

SWITCH(

    TRUE (),

    [*Sales Last 7 Days vs 60 Day Avg]>0

    && [*Sales 2 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 3 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 4 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 5 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 6 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 7 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 8 Weeks Prior vs 60 Day Avg]>0 ,8,

 

   [*Sales Last 7 Days vs 60 Day Avg]>0

    && [*Sales 2 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 3 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 4 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 5 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 6 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 7 Weeks Prior vs 60 Day Avg]>0,7,

 

    [*Sales 2 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 3 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 4 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 5 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 6 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 7 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 8 Weeks Prior vs 60 Day Avg]>0 ,7,

 

   [*Sales Last 7 Days vs 60 Day Avg]>0

    && [*Sales 2 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 3 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 4 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 5 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 6 Weeks Prior vs 60 Day Avg]>0,6,

 

    [*Sales 3 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 4 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 5 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 6 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 7 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 8 Weeks Prior vs 60 Day Avg]>0 ,6,

 

    [*Sales 2 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 3 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 4 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 5 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 6 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 7 Weeks Prior vs 60 Day Avg]>0,6,

 

     [*Sales Last 7 Days vs 60 Day Avg]>0

    && [*Sales 2 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 3 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 4 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 5 Weeks Prior vs 60 Day Avg]>0,5,

 

    [*Sales 2 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 3 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 4 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 5 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 6 Weeks Prior vs 60 Day Avg]>0,5,

 

    [*Sales 3 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 4 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 5 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 6 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 7 Weeks Prior vs 60 Day Avg]>0,5,

 

    [*Sales 4 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 5 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 6 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 7 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 8 Weeks Prior vs 60 Day Avg]>0 ,5,

 

    [*Sales Last 7 Days vs 60 Day Avg]>0

    && [*Sales 2 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 3 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 4 Weeks Prior vs 60 Day Avg]>0, 4,

 

    [*Sales 2 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 3 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 4 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 5 Weeks Prior vs 60 Day Avg]>0, 4,

 

    [*Sales 3 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 4 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 5 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 6 Weeks Prior vs 60 Day Avg]>0, 4,

 

    [*Sales 4 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 5 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 6 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 7 Weeks Prior vs 60 Day Avg]>0, 4,

 

    [*Sales 5 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 6 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 7 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 8 Weeks Prior vs 60 Day Avg]>0 ,4,

 

    [*Sales Last 7 Days vs 60 Day Avg]>0

    && [*Sales 2 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 3 Weeks Prior vs 60 Day Avg]>0,3,

 

    [*Sales 2 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 3 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 4 Weeks Prior vs 60 Day Avg]>0,3,

 

     [*Sales 3 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 4 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 5 Weeks Prior vs 60 Day Avg]>0,3,

 

    [*Sales 4 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 5 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 6 Weeks Prior vs 60 Day Avg]>0,3,

 

    [*Sales 5 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 6 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 7 Weeks Prior vs 60 Day Avg]>0,3,

 

    [*Sales 6 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 7 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 8 Weeks Prior vs 60 Day Avg]>0 ,3,

 

    [*Sales Last 7 Days vs 60 Day Avg]>0

    && [*Sales 2 Weeks Prior vs 60 Day Avg]>0,2,

 

    [*Sales 2 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 3 Weeks Prior vs 60 Day Avg]>0,2,

 

    [*Sales 3 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 4 Weeks Prior vs 60 Day Avg]>0,2,

 

    [*Sales 4 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 5 Weeks Prior vs 60 Day Avg]>0,2,

 

    [*Sales 5 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 6 Weeks Prior vs 60 Day Avg]>0,2, 

 

    [*Sales 6 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 7 Weeks Prior vs 60 Day Avg]>0,2,

 

    [*Sales 7 Weeks Prior vs 60 Day Avg]>0

    && [*Sales 8 Weeks Prior vs 60 Day Avg]>0 ,2,

 

BLANK())

Hi @Jansco ,

If you can please share a sample pbix file for test, it is hard to modify dax formula without any detail sample data.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.