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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Sefino535
Frequent Visitor

Count of days with losses

Hello guys,

 

I hope you can help me to write a formula that tells me how many days I have lost on the individual products in the past 30 days. The formula should identify today's day -30 so it will be automatically rolling that past. 

Data contain a day calendar and the days without losses are 0 (zero) and lost is a number per day. 

 

ID_ ProdLoss in the past 30 days
Prod 110
Prod 23
Prod 323
Prod 40
Prod 515

 

If you got any further questions feel free to ask. 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please try writing a measure something like below.

 

DayLost Measure: =
CALCULATE (
    COUNTROWS ( FILTER ( DISTINCT ( 'Calendar'[Date] ), [Losses] <> 0 ) ),
    DATESINPERIOD ( 'Calendar'[Date], TODAY (), -30, DAY )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

7 REPLIES 7
Jihwan_Kim
Super User
Super User

Hi,

Please try writing a measure something like below.

 

DayLost Measure: =
CALCULATE (
    COUNTROWS ( FILTER ( DISTINCT ( 'Calendar'[Date] ), [Losses] <> 0 ) ),
    DATESINPERIOD ( 'Calendar'[Date], TODAY (), -30, DAY )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Thanks Jihwan_Kim,

 

Your solution works perfectly as expected! The formula does not count single rows, but days of losses. 

 

Many help you are top! 

Sefino535
Frequent Visitor

Hi guys, 

 

Any suggestion for this problem? I looked up anywhere and I can't get It to work it! Still get more losses than up 30 days, caused by different types of loss = multiple rows counts.

I wish to count any loss of a day as one day lost out of the past 30 days. 

 

Sefino535_0-1670791259768.png

 

I hope it make sense. 

FreemanZ
Super User
Super User

hi @Sefino535 

 

try to create a measure with this:

DaysLost =
CALCULATE(
    COUNTROWS(
        FILTER(
            TableName,
            TableName[Loss]<>0
        )
     ),
    DATESINPERIOD(Calendar[Date], TODAY(), -30, DAY)
)

 

Hi FreemanZ,

 

I have an issue, with a calculation, I have more "days lost" than 30 which should be the maximum. Could it be that there is also a customer-level loss? Can we narrow it down to loss on Material ID? 

 

See the below result...

 

Sefino535_0-1670674589023.png

 

the issue of "more "days lost" than 30" depends on your data model, it is possible when there were multiple records/rows per day. 

Can we narrow it down to loss on Material ID? That also depends on your model. The measure itself has nothing to do with Material ID. 

 

A piece of advice:

when testing new measures, try with simple setup first, like a table visual with one field plus the measure only. 

Hi,

...well is possible that model has more rows per day as a loss. Any Idea how to overcome this this so it will count all losses in a day as "one day" ? 
Anyone help appreciate! 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.