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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
BobbyKothari1
Frequent Visitor

Dax formula for summing up the days with stop condition.

Hi, How can we calculate the total days in below table where we want to add up the days from each week, but only until we find the first week where the number of days is less than 7. Once we find that week, we'll stop adding up the days. So, we're summing up the days, but we'll only include weeks where the days are less than 7 until we hit the first week where the days are less than 7, and then we'll stop.
like in this case result should be 33.6 days because we are adding days till week 4 and week 4 is first week where days are less than 7 days.

 Week  Days 
              -                     7.0
                1                   7.0
                2                   7.0
                3                   7.0
                4                   5.6
                5                   7.0
                6                   7.0
                7                   7.0
                8                   7.0
                9                   1.0
             10                   7.0

 

1 ACCEPTED SOLUTION

hi @BobbyKothari1 

 

Assumption : Need unique key for this data. I am assumin that combinatio of code and Week is unique.

 

Using the data which you shared, please create this measure.

 

DaysTotal =
VAR _Code = SELECTEDVALUE(Test3[Code])
VAR _SummTbl =
ADDCOLUMNS(
            SUMMARIZE(ALL(Test3[Code], Test3[Week]), Test3[Code], Test3[Week]),
            "@RevenueDays",
            VAR _code = [Code]
            VAR _Week = [Week]
            RETURN CALCULATE([Revenue days], REMOVEFILTERS(), Test3[Code] = _code && Test3[Week] = _Week)
)

VAR _Week = MINX( FILTER(_SummTbl, [Code] = _Code && [@RevenueDays] <> 7), [Week])
RETURN SUMX( FILTER(_SummTbl, [Code] = _Code && [Week] <= _Week), [@RevenueDays])
 
talespin_0-1711185831646.png

 

View solution in original post

7 REPLIES 7
BobbyKothari1
Frequent Visitor

Hi @talespin i am having an below error may be because my week[days] is measure instead of column, is there any way to resolve this error.

 

BobbyKothari1_0-1711035642194.png

 

hi @BobbyKothari1 

 

What is in the measure week[days] ?

Hi @talespin below is the formula i have been using for days calculation and i want stop this calculation at week 4 as per the above condition we have discussed.
Days formula-

Revenue days =
Var Total_Inventory=SUM(data[Inventory])
VAR Total_Revenue=SUM(data[Revenue])
Var Total_cumulative_Revenue=SUM(data[Cumulative Revenue])
Var Remaining_inventory=Total_Inventory-Total_cumulative_Revenue
Var Revenue_Week = if(Remaining_inventory>=0,7,0)
Var additional_days= IF(AND(Total_cumulative_Revenue>Total_Inventory,Total_Revenue+Remaining_inventory>0),((Total_Revenue+Remaining_inventory)/Total_Revenue)*7,0)
RETURN
if(Total_Inventory<=0,0,Revenue_Week+additional_days)

BobbyKothari1_1-1711088399298.png

Data for your Ref

CodeInventoryWeekRevenueCumulative RevenueRemaining Inventory
557,31,71,800058,17,47158,17,4716,73,54,309
557,31,71,800173,29,7551,31,47,2266,00,24,554
557,31,71,80021,21,22,0292,52,69,2554,79,02,525
557,31,71,80031,14,92,0363,67,61,2913,64,10,489
557,31,71,80044,54,06,7678,21,68,058-89,96,278
557,31,71,8005-3,82,01,8194,39,66,2392,92,05,541
557,31,71,80061,22,82,4395,62,48,6781,69,23,102
557,31,71,800793,34,7886,55,83,46675,88,314
557,31,71,800860,53,2247,16,36,69015,35,090
557,31,71,80091,12,63,9048,29,00,594-97,28,814
557,31,71,800101,11,88,8189,40,89,412-2,09,17,632
557,31,71,800111,24,16,76610,65,06,178-3,33,34,398
557,31,71,800121,27,96,93411,93,03,112-4,61,31,332
557,31,71,800131,52,30,17213,45,33,284-6,13,61,504
557,31,71,800141,34,41,11414,79,74,398-7,48,02,618
557,31,71,800152,88,42,30117,68,16,699-10,36,44,919
557,31,71,800161,48,54,79219,16,71,491-11,84,99,711
557,31,71,800171,48,31,59720,65,03,088-13,33,31,308
557,31,71,800181,66,38,01322,31,41,101-14,99,69,321
557,31,71,800192,30,03,77424,61,44,875-17,29,73,095
557,31,71,800201,85,93,85526,47,38,730-19,15,66,950
557,31,71,800211,37,09,02227,84,47,752-20,52,75,972
557,31,71,800221,68,95,33129,53,43,083-22,21,71,303
557,31,71,800232,32,59,16831,86,02,251-24,54,30,471
557,31,71,800241,68,16,34633,54,18,597-26,22,46,817
557,31,71,800251,38,07,58034,92,26,177-27,60,54,397
557,31,71,8002689,06,72035,81,32,897-28,49,61,117
557,31,71,800274,32,62835,85,65,525-28,53,93,745
557,31,71,800283,63,61,96939,49,27,494-32,17,55,714
557,31,71,80029-55,20,02038,94,07,474-31,62,35,694
557,31,71,800303,16,54,10342,10,61,577-34,78,89,797
557,31,71,800312,74,69,06744,85,30,644-37,53,58,864
557,31,71,800321,61,60,11646,46,90,760-39,15,18,980
557,31,71,800331,34,76,35847,81,67,118-40,49,95,338
557,31,71,800341,25,20,10049,06,87,218-41,75,15,438
557,31,71,800351,49,68,69850,56,55,916-43,24,84,136
557,31,71,800362,98,47,41553,55,03,331-46,23,31,551
557,31,71,800371,11,17,58554,66,20,916-47,34,49,136
557,31,71,800382,38,21,25557,04,42,171-49,72,70,391
557,31,71,80039-2,08,97,65754,95,44,514-47,63,72,734
557,31,71,8004066,03,25655,61,47,770-48,29,75,990
557,31,71,800411,56,04,98857,17,52,758-49,85,80,978
557,31,71,800421,00,27,70258,17,80,460-50,86,08,680
557,31,71,80043-18,75,31757,99,05,143-50,67,33,363
557,31,71,80044-8,49,58,45549,49,46,688-42,17,74,908
557,31,71,8004511,51,19,61161,00,66,299-53,68,94,519
557,31,71,800464,10,82,27965,11,48,578-57,79,76,798
557,31,71,80047-33,88,41964,77,60,159-57,45,88,379
557,31,71,800481,68,14,29766,45,74,456-59,14,02,676
557,31,71,800494,33,92,37270,79,66,828-63,47,95,048
557,31,71,800501,01,55,01171,81,21,839-64,49,50,059
557,31,71,800511,49,98,24573,31,20,084-65,99,48,304
557,31,71,800522,91,62,68576,22,82,769-68,91,10,989
 

 

hi @BobbyKothari1 

 

Assumption : Need unique key for this data. I am assumin that combinatio of code and Week is unique.

 

Using the data which you shared, please create this measure.

 

DaysTotal =
VAR _Code = SELECTEDVALUE(Test3[Code])
VAR _SummTbl =
ADDCOLUMNS(
            SUMMARIZE(ALL(Test3[Code], Test3[Week]), Test3[Code], Test3[Week]),
            "@RevenueDays",
            VAR _code = [Code]
            VAR _Week = [Week]
            RETURN CALCULATE([Revenue days], REMOVEFILTERS(), Test3[Code] = _code && Test3[Week] = _Week)
)

VAR _Week = MINX( FILTER(_SummTbl, [Code] = _Code && [@RevenueDays] <> 7), [Week])
RETURN SUMX( FILTER(_SummTbl, [Code] = _Code && [Week] <= _Week), [@RevenueDays])
 
talespin_0-1711185831646.png

 

Thanks @talespin really appreciate your help

hi @BobbyKothari1 

 

A correction is needed, please check the measure above. I forgot to added filter on code.

 

My Apology.

talespin
Solution Sage
Solution Sage

hi @BobbyKothari1 

 

Please check, this is a measure

 

DaysTotal =
VAR _Week = CALCULATE( MIN(Week[Week ]), REMOVEFILTERS(), Week[ Days ] <> 7)
RETURN CALCULATE( SUM(Week[ Days ]), REMOVEFILTERS(), Week[Week ] <= _Week)

 

talespin_0-1711018529593.png

 

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors