cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mandy4514
Helper I
Helper I

create variable from collection that could be blank and put a zero if blank?

So I have a variable that works

Set(
    varBuildingDailyCount,
    Filter(
        collectionDailyLog,
        FieldDate = varCurrentDate && Building = varBuilding.Value
    ).NumberPerday
)

This works to bring back the value of number per day. My issue is that sometimes that number does not exist and I need to set the value to zero. If I alter the formula with an if, I cannot seem to set the table value to zero if blank.

   Set(varDailyCount, If(IsBlank(Filter(
        collectionDailyLog,
        FieldDate = varCurrentDate && Building = varBuilding.Value
    ).NumberPerday
),0,
    Filter(
        collectionDailyLog,
        FieldDate = varCurrentDate && Building = varBuilding.Value
    ).NumberPerday
))

Any and all help would be appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@mandy4514 

To be clear, in your set formula, you are setting your variable to a table, not a value.  If you want just a value, then you need to utilize the LookUp function and not the Filter function.

ex. with LookUp and also Coalesce to provide the 0 value if blank.

Set(
    varBuildingDailyCount,
    Coalesce(
        LookUp(collectionDailyLog,
            FieldDate = varCurrentDate && Building = varBuilding.Value,
            NumberPerday
        ),
        0
    )
)

 

If it truly is a Table that you want in your variable, then you can implement this:

Set(
    varBuildingDailyCount,
    ForAll(
        Filter(collectionDailyLog,
            FieldDate = varCurrentDate && Building = varBuilding.Value
        ).NumberPerday,
        {NumberPerday: Coalesce(NumberPerday, 0)}
    )
)

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

1 REPLY 1
RandyHayes
Super User
Super User

@mandy4514 

To be clear, in your set formula, you are setting your variable to a table, not a value.  If you want just a value, then you need to utilize the LookUp function and not the Filter function.

ex. with LookUp and also Coalesce to provide the 0 value if blank.

Set(
    varBuildingDailyCount,
    Coalesce(
        LookUp(collectionDailyLog,
            FieldDate = varCurrentDate && Building = varBuilding.Value,
            NumberPerday
        ),
        0
    )
)

 

If it truly is a Table that you want in your variable, then you can implement this:

Set(
    varBuildingDailyCount,
    ForAll(
        Filter(collectionDailyLog,
            FieldDate = varCurrentDate && Building = varBuilding.Value
        ).NumberPerday,
        {NumberPerday: Coalesce(NumberPerday, 0)}
    )
)

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (2,264)