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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Newbobotime
Frequent Visitor

Wrong measurement with IF

Hi everyone,
I have a problem, maybe it's simple but I don't understand how to solve it.

I present the data for this measure in a table in which I would like to calculate the percentage of a hypothetical number of completed orders.
For some strange reason completed orders always seem to be higher than total orders so I thought I'd put an IF; if the result of the completed orders count is greater than the total orders count, do the total orders count, otherwise do the completed orders count.
If I look at the data presented for each record it seems correct but the total sum does not add up, it does not remove the excess numbers.

 

total_order =
VAR new = CALCULATE(COUNTX(order_new, order_new [code]))
VAR complete = CALCULATE(COUNTX(order_complete, order_complete[code]))
VAR result = IF(new > complete, new, complete)
RETURN
result

 

1 ACCEPTED SOLUTION
Newbobotime
Frequent Visitor

Maybe I solved it.
Sure the code could be written better but it seems to work.
First of all I created a new table with summarize, determining the total orders and for the completed orders data I performed a comparison with the IF.
Subsequently I created the various measurements using this table

summarize.png

View solution in original post

11 REPLIES 11
Newbobotime
Frequent Visitor

Perhaps there is a more correct method but I think I solved it by creating a table with "Summarize" and then setting the various measures; total orders, total_completed_orders, %completed_orders
summarize.png

Newbobotime
Frequent Visitor

Maybe I solved it.
Sure the code could be written better but it seems to work.
First of all I created a new table with summarize, determining the total orders and for the completed orders data I performed a comparison with the IF.
Subsequently I created the various measurements using this table

summarize.png

Anonymous
Not applicable

Hi, @Newbobotime 

Thank you very much for your reply and the solution you shared. I decided it was a great idea to create a summary table. You can mark your response as a solution so that others in the community can quickly find a solution if they encounter a similar problem. Thanks again for sharing!

 

 

Best Regards

Jianpeng Li

Newbobotime
Frequent Visitor

with a simple "IF", I solve the percentage problem for each record but the subtotal is wrong

Anonymous
Not applicable

Hi, @Newbobotime 

Thank you very much for your reply. You can try sumx to get the correct total, and your new Total Orders completed_IF measure might look like this:

Total_Orders_Completed_IF =
SUMX ( 'LOCATION_CODE', [Total Orders completed_IF] )

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Pavel_Gutsol
New Member

Please, try this version:

total_order =
VAR new =
CALCULATE ( COUNTX ( VALUES ( order_new[code] ), order_new[code] ) )
VAR complete =
CALCULATE ( COUNTX ( VALUES ( order_complete[code] ), order_complete[code] ) )
VAR result =
IF ( new > complete, new, complete )
RETURN
result

 

Thanks Pavel, for the help but it doesn't work,
I assume this way it can't iterate, it proposes the same number for all records 🙄

Anonymous
Not applicable

Thanks @Pavel_Gutsol 

Hi, @Newbobotime 

Can you make some sample data for your problem, and what results do you expect? What fields do you use this metric in your table visual, and what are the contexts it depends on? It would be helpful to have some explanation of the sample data you provided that you expect the results to be. When providing sample data, please do not include any privacy data. Here's a sample I created:

order_new table:

vjianpengmsft_0-1713236924264.png

order_complete table:

vjianpengmsft_1-1713236964675.png

I use the following DAX expression to find the percentage of completion to new:

Percentage =
VAR _all_new =
    CALCULATE ( COUNTAX ( 'order_new', 'order_new'[code] ), ALL ( order_new ) )
VAR _selected_code =
    SELECTEDVALUE ( order_complete[code] )
VAR _complete =
    CALCULATE (
        COUNTAX (
            FILTER ( ALL ( 'order_complete' ), 'order_complete'[code] <= _selected_code ),
            'order_complete'[code]
        )
    )
RETURN
    DIVIDE ( _complete, _all_new )

vjianpengmsft_2-1713237147392.png

Also, you mentioned that in your table visual, total doesn't work, I used the DAX formula you provided here and created a total measure:

Total = SUMX('order_complete',[total_order]) 

vjianpengmsft_3-1713237347894.png

 

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

over_100%.png

I would like to get an output like this, where however the total number of completed orders can only be equal to or less than the orders.

I take data from two tables orders and completed orders, I don't want to identify duplicate data, I just want to count orders by day and location for the two tables and get a maximum of 100%

As I wrote at the beginning I thought of simply solving with an IF, but that's not possible.

I assume I need to create a virtual table with both data; orders and completed orders, and then set an IF condition.

wrong_sum.png

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.