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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
SPDA
New Member

Help with adding if then statement?

Hello,

 

I am new to creating measures and have hit a wall. Can anyone help?


I've created a measure that works properly to calculate the sum of a field called AgrHrsCovered for Jan 2025 only.

I need to add a caveat that if the hours are less than 1 to return 1 as the sum. If 1 or more then follow the calculation for sum. 

 

Thank you!

 

Jan 2025 Hrs =

CALCULATE (

    SUM ('EHR Hours'[AgrHrsCovered] ),

    'EHR Hours'[Date Start] >= DATE(2025,1,1) &&

    'EHR Hours'[Date Start] <= DATE(2025,1,31)

   

)

 

1 ACCEPTED SOLUTION

Can you provide a sample of the data please? It may be better to use a calculated column that only performs the if statement, depending on how your data is presented

Here i've used the column
CalculatedColumn = IF('January2025Hours'[Hours] < 1, 1, 'January2025Hours'[Hours])

 

to obtain the following results

 

wardy912_0-1750447503139.png

Let me know if this fixes the issue, thanks

View solution in original post

8 REPLIES 8
v-pnaroju-msft
Community Support
Community Support

Thank you, @wardy912@mfed, for your response.

Hi SPDA,

We appreciate your inquiry raised through the Microsoft Fabric Community Forum.

Based on my understanding of the issue, please find attached a screenshot along with a sample PBIX file, which may assist in resolving the problem:

vpnarojumsft_0-1750663935508.png

If you find our response helpful, kindly mark it as the accepted solution and provide kudos. This will help other community members who may have similar queries. However, if the response does not address your requirements, please provide sample data that clearly illustrates your issue or question in a usable format (and not as a screenshot). Kindly ensure that the data shared does not contain any sensitive or unrelated information. Additionally, please indicate the expected outcome based on the sample data provided.

Should you have any further questions or concerns, please feel free to reach out to the Microsoft Fabric Community.

Thank you.

SPDA
New Member

Hey, thanks, wardy912. That looks like it makes sense to me, but when I compared the new (TEST Jan 2025 Hrs)  to the original (Jan 2024 Hrs) it isn't doing what I want:

SPDA_0-1750432422493.png

 

Can you provide a sample of the data please? It may be better to use a calculated column that only performs the if statement, depending on how your data is presented

Here i've used the column
CalculatedColumn = IF('January2025Hours'[Hours] < 1, 1, 'January2025Hours'[Hours])

 

to obtain the following results

 

wardy912_0-1750447503139.png

Let me know if this fixes the issue, thanks

mfed
Frequent Visitor

Agree with Wardy 912.

 

Just for another angle on this same solution, you would probably have a measure for your SUM of EHR hours anyway, (same as the Variable created above and so you can use it elsewhere), so you can then write the same IF statement using that measure in the same way as the variable is used above. Just another way of looking at it. 

Thanks for the input! I wasn't sure if I could reference measures in measures.

mfed
Frequent Visitor

Yes, for sure - in fact in my training it was best practice to create a 'Measure Table' with as many measures as you thought you might need, then you can reference them on their own or in other measures. It's a standalone table in the data model with all your individual measures, and once you have that it sits right at the top of your 'Data' section on your main screen.

Nice, I'll add that to my practice. Appreciate the tip!

wardy912
Resolver II
Resolver II

Hi @SPDA 

 

Jan 2025 Hrs = 
VAR TotalHrs = 
    CALCULATE (
        SUM ('EHR Hours'[AgrHrsCovered]),
        'EHR Hours'[Date Start] >= DATE(2025,1,1) &&
        'EHR Hours'[Date Start] <= DATE(2025,1,31)
    )
RETURN
    IF (TotalHrs < 1, 1, TotalHrs)

The return statement gives 1 if true, the actual sum if false.

 

Hope this helps, please mark as the solution and give a thumbs up if it does, thanks!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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