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
lsullivan6311
Helper III
Helper III

Create IF measure summing one column based on another column

I need a measure that states:

 

If this Table1[company ID] = “1055”, then

Do this calculation:

 

Calculate(

    SUM(Table1[count]) * 0.50,Table1[PrdType] = "Unit Production")

 

Else do this calculation:

Calculate(

    SUM(Table1[count]),Table1[PrdType] = "Unit Production")

 

 

 

So basically one company production units are 50% and the rest are summed at 100%. 

 

My measure I tried is below:

 

ProdUnits = IF(Table1[company ID]="1055", Calculate(

    SUM(Table1[count])*0.50,Table1[PrdType] = "Unit Production"),
    Calculate(

       SUM(Table1[count]),Table1[PrdType] = "Unit Production"))

 

I get the following error:

 

! A single value for column ‘company ID’ in Table ‘Table1’ cannot be determined.  This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, count, or sum to get a single result.

 

Please note that company ID format is TEXT, not a number.  I don’t know how I would aggregate a TEXT even if the text is a number.  I cannot provide my tables.

1 ACCEPTED SOLUTION

I appreciate your work on this.  This seems to be the same as what I had done yesterday.  The measure seems to be working without errors; however, I do not get any results.  I think I will break the measure apart to understand what part is breaking for my larger tables.  I appreciate the assistance.

View solution in original post

10 REPLIES 10
lsullivan6311
Helper III
Helper III

It turns out I had a filter on the table causing my problem, user error!

lsullivan6311
Helper III
Helper III

 why MAX on a TEXT column?

Samarth_18
Community Champion
Community Champion

HI @lsullivan6311 ,

Please try this:-

ProdUnits =
IF (
    MAX ( Table1[company ID] ) = "1055",
    CALCULATE (
        SUM ( Table1[count] ) * 0.50,
        FILTER ( Table1, Table1[PrdType] = "Unit Production" )
    ),
    CALCULATE (
        SUM ( Table1[count] ),
        FILTER ( Table1, Table1[PrdType] = "Unit Production" )
    )
)

BR,

Samarth

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

I tried this measure and although I do not get an error message for the measure, I also do not have any values returned either.  The measure is completely blank in my visualization.

@lsullivan6311 Can you please share the sample data in text format with expected output?

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

It is not allowing me to load a sample data set

 

company ID      PrdType                      Count      dateend

1055                  Unit Production         16438       12/31/2021

1055                  Unit Production         18540        11/30/2021

1055                  Unit Production          18516       10/31/2021

1343                  Unit Production          11029       12/31/2021

1343                  Unit Production          18554       11/30/2021

1343                  Unit Production           10503       10/31/2021

 

 

@lsullivan6311 Please refer the attached file.

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

I appreciate your work on this.  This seems to be the same as what I had done yesterday.  The measure seems to be working without errors; however, I do not get any results.  I think I will break the measure apart to understand what part is breaking for my larger tables.  I appreciate the assistance.

I have a followup issue.  The measure now works on the specific row; however, the sum of the column is still the total, it does not consider the measure calculation.  How can I get the sum to match the numbers in the column?

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.