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
BI_Noob
Frequent Visitor

Sum by multiple filters for hour range

Please Help

I have a large dataset with sales information aggregated by date, store#, and most imporantly by hour. See example below;

DateStoreIdHourOnline OrdersPhone OrdersTotal Orders
1-Jan11150147197
1-Jan21050200250
1-Jan1130210210
1-Jan11215175190
1-Jan2130275275
1-Jan2110108108
1-Jan11007575
1-Jan21408989

 

This dataset is not ordered - essentially - I'm trying to create a column flag of T/F to identify when a store has 3 consecutive hours of NO digital sales but Total Orders were over X. 

=AND(SUMIFS(OnlineOrders,DATE,[@DATE],StoreId,[@StoreId],Hour,OR([@Hour],[@Hour]+1,[@Hour]-1)) = 0, SUMIFS(TotalOrders,DATE,[@DATE],StoreId,[@StoreId],Hour,OR([@Hour],[@Hour]+1,[@Hour]-1)) > X

 

Can someone please help?

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@BI_Noob,

 

Here's a pattern for a calculated column. You can adjust the threshold variable as well as the logic for handling cases where three consecutive hours don't exist.

 

Flag = 
VAR vThreshold = 175
VAR vHour = Table1[Hour]
VAR vTotalOrders = Table1[Total Orders]
VAR vOnlineOrdersLast3Hours =
    CALCULATE (
        SUM ( Table1[Online Orders] ),
        ALLEXCEPT ( Table1, Table1[Date], Table1[StoreId] ),
        Table1[Hour] >= vHour - 2,
        Table1[Hour] <= vHour
    )
VAR vResult =
    IF ( vOnlineOrdersLast3Hours == 0 && vTotalOrders > vThreshold, "T", "F" )
RETURN
    vResult

 

DataInsights_1-1651334014660.png

 





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

Proud to be a Super User!




View solution in original post

2 REPLIES 2
DataInsights
Super User
Super User

@BI_Noob,

 

Here's a pattern for a calculated column. You can adjust the threshold variable as well as the logic for handling cases where three consecutive hours don't exist.

 

Flag = 
VAR vThreshold = 175
VAR vHour = Table1[Hour]
VAR vTotalOrders = Table1[Total Orders]
VAR vOnlineOrdersLast3Hours =
    CALCULATE (
        SUM ( Table1[Online Orders] ),
        ALLEXCEPT ( Table1, Table1[Date], Table1[StoreId] ),
        Table1[Hour] >= vHour - 2,
        Table1[Hour] <= vHour
    )
VAR vResult =
    IF ( vOnlineOrdersLast3Hours == 0 && vTotalOrders > vThreshold, "T", "F" )
RETURN
    vResult

 

DataInsights_1-1651334014660.png

 





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

Proud to be a Super User!




I cannot appreciate this enough!

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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