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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

Sum of the quantity in the SKU level for last 30 days

Hi all,

 

I would like to sum the quantity in the SKU level for last 30 days from today(), for each sales channel. 

The data table (example) looks like that:

Nawaz_0-1645182486202.png

I tried with this measure, but still, this is not done. Can anyone help me out with how to get the right result?

 

QuantityLast30Day =
CALCULATE (
SUM ( flatFileOrders[quantity]),
DATESINPERIOD (flatFileOrders[updatedAt], MAX(flatFileOrders[updatedAt]), -30, DAY )
)
 

I tried to see this link: Calculate Sales Past 30 Days, but it is not fulfilling the requirements.

Regards,

Ahsan

1 ACCEPTED SOLUTION

@Anonymous if you dont have calender table with below code: based on requirement-

calender("01/01/2020","01/01/2025")

or else you can try below code:-

QuantityLast30Day =
VAR max_date =
    MAX ( flatFileOrders[updateat] )
VAR last_30days =
    MAX ( flatFileOrders[updateat] ) - 30
RETURN
    CALCULATE (
        SUM ( flatFileOrders[quantity] ),
        FILTER (
            flatFileOrders,
            flatFileOrders[updateat] <= max_date
                && flatFileOrders[updateat] >= last_30days
        )
    )

 

  

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

View solution in original post

3 REPLIES 3
Samarth_18
Community Champion
Community Champion

Hi @Anonymous ,

 

Use your date table inside dateperiod function.

 

QuantityLast30Day =
CALCULATE (
SUM ( flatFileOrders[quantity]),
DATESINPERIOD (Datetable[date], MAX(Datetable[date]), -30, DAY )
)

 

Thanks,

Samarth

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Anonymous
Not applicable

Hi @Samarth_18 , 

 

i don't have a separate date table in my data model. 

Do, i need to create a date table? if yes, can you please tell me how to do it?

I'm not very experienced in Power BI.

Thanks.

@Anonymous if you dont have calender table with below code: based on requirement-

calender("01/01/2020","01/01/2025")

or else you can try below code:-

QuantityLast30Day =
VAR max_date =
    MAX ( flatFileOrders[updateat] )
VAR last_30days =
    MAX ( flatFileOrders[updateat] ) - 30
RETURN
    CALCULATE (
        SUM ( flatFileOrders[quantity] ),
        FILTER (
            flatFileOrders,
            flatFileOrders[updateat] <= max_date
                && flatFileOrders[updateat] >= last_30days
        )
    )

 

  

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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