cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Helper II

What is the additional if statement that will return the first-non zero value from previous row?

I am currently doing a COVID-19 reports/dashboard through Power BI. I have this dax formula that will return the new cases for each day. However, the problem with this formula is that I am not able to return the value of the first case - it returns 0. May I ask for suggestion on how to make this formula return the value of first case as well?

Source code:

```New_Cases =
VAR Countries = ConfirmedCases[Country/Region]
VAR State = ConfirmedCases[Province/State]
VAR dates = ConfirmedCases[Date]
VAR PrevDay =
CALCULATE(
MAX(ConfirmedCases[Cases]),
FILTER('ConfirmedCases',
ConfirmedCases[Country/Region]=Countries && ConfirmedCases[Province/State]=State && ConfirmedCases[Date]<dates))
RETURN
IF(PrevDay=0,0,
IF(PrevDay>[Cases],0,
IF(PrevDay>0,[Cases]-PrevDay)))```

Here is the current output:

1 ACCEPTED SOLUTION
Helper II

We got the answer! Sharing the appropriate solution:

New_Cases =
VAR Countries = Confirmed_Cases[Country/Region]
VAR State = Confirmed_Cases[Province/State]
VAR dates = Confirmed_Cases[Date]
VAR tbl =   FILTER('Confirmed_Cases',
Confirmed_Cases[Country/Region]=Countries && Confirmed_Cases[Province/State]=State && Confirmed_Cases[Date]<dates)
VAR PrevDay =
CALCULATE(
MAX(Confirmed_Cases[Cases]),
tbl)
RETURN
[Cases] - PrevDay
3 REPLIES 3
Helper II

We got the answer! Sharing the appropriate solution:

New_Cases =
VAR Countries = Confirmed_Cases[Country/Region]
VAR State = Confirmed_Cases[Province/State]
VAR dates = Confirmed_Cases[Date]
VAR tbl =   FILTER('Confirmed_Cases',
Confirmed_Cases[Country/Region]=Countries && Confirmed_Cases[Province/State]=State && Confirmed_Cases[Date]<dates)
VAR PrevDay =
CALCULATE(
MAX(Confirmed_Cases[Cases]),
tbl)
RETURN
[Cases] - PrevDay
Super User

@ironboy0418 , Previous date when cases were 0 (New column)

New_Cases =
VAR Countries = ConfirmedCases[Country/Region]
VAR State = ConfirmedCases[Province/State]
VAR dates = ConfirmedCases[Date]
VAR PrevDay =
CALCULATE(
MAX(ConfirmedCases[dates]),
FILTER('ConfirmedCases',
ConfirmedCases[Country/Region]=Countries && ConfirmedCases[Province/State]=State && ConfirmedCases[Date]<dates && ConfirmedCases[New_Cases]=0))
RETURN
PrevDay

1st date when case were 0

New_Cases =
VAR Countries = ConfirmedCases[Country/Region]
VAR State = ConfirmedCases[Province/State]
VAR dates = ConfirmedCases[Date]
VAR PrevDay =
CALCULATE(
Min(ConfirmedCases[dates]),
FILTER('ConfirmedCases',
ConfirmedCases[Country/Region]=Countries && ConfirmedCases[Province/State]=State && ConfirmedCases[Date]<dates && ConfirmedCases[New_Cases]=0))
RETURN
PrevDay

Helper II

Thanks amitchandak! Do I need to create two columns for these?

Announcements

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.

Power BI Monthly Update - June 2024

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

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors
Top Kudoed Authors