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
mmar141
Frequent Visitor

Help with adding columns

Hello,

I'm a very new user to power bi (about 2 weeks) and am running into some issues with my first report.  I have 3 tables that all calculate a pass / fail column if certain conditions are met.   (see simplified example)

mmar141_1-1688831430444.png

 

I want to have a main reporting page with a transposed table containing the pass fail metrics along with the percentages like this

mmar141_2-1688831477488.png

 

I've tried building a new table using SelectColumns/Add Columns, but it keeps giving me error like 
"A single value for column 'Pass_Fail" 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, max, count or sum to get a single result"

 

I'm fairly certain I'm using the wrong approach to get the data together in one place.  Can anyone help?  Would converting pass fail to binary be the correct approach? If so, how would I approach the <Null> values?

 

1 ACCEPTED SOLUTION

Hi @mmar141 ,

If you mean the data type in Table1, Table2 and Table3 is Date, but in the new created table is text, here's my solution.

1.Delete the relationships betwen the four tables.

vyanjiangmsft_0-1689154390775.png

2.Modify the measure to:

Measure =
SWITCH (
    MAX ( 'Table'[TableName] ),
    "Table1",
        IF (
            MAX ( 'Date'[Date] ) = "%",
            DIVIDE (
                COUNTROWS ( FILTER ( ALL ( 'Table1' ), 'Table1'[Calculated Pass/Fail] = "P" ) ),
                COUNTROWS (
                    FILTER ( ALL ( 'Table1' ), 'Table1'[Calculated Pass/Fail] <> BLANK () )
                )
            ),
            MAXX (
                FILTER ( 'Table1', 'Table1'[Date] = CONVERT ( MAX ( 'Date'[Date] ), DATETIME ) ),
                'Table1'[Calculated Pass/Fail]
            )
        ),
    "Table2",
        IF (
            MAX ( 'Date'[Date] ) = "%",
            DIVIDE (
                COUNTROWS ( FILTER ( ALL ( 'Table2' ), 'Table2'[Calculated Pass/Fail] = "P" ) ),
                COUNTROWS (
                    FILTER ( ALL ( 'Table2' ), 'Table2'[Calculated Pass/Fail] <> BLANK () )
                )
            ),
            MAXX (
                FILTER ( 'Table2', 'Table2'[Date] = CONVERT ( MAX ( 'Date'[Date] ), DATETIME ) ),
                'Table2'[Calculated Pass/Fail]
            )
        ),
    "Table3",
        IF (
            MAX ( 'Date'[Date] ) = "%",
            DIVIDE (
                COUNTROWS ( FILTER ( ALL ( 'Table3' ), 'Table3'[Calculated Pass/Fail] = "P" ) ),
                COUNTROWS (
                    FILTER ( ALL ( 'Table3' ), 'Table3'[Calculated Pass/Fail] <> BLANK () )
                )
            ),
            MAXX (
                FILTER ( 'Table3', 'Table3'[Date] = CONVERT ( MAX ( 'Date'[Date] ), DATETIME ) ),
                'Table3'[Calculated Pass/Fail]
            )
        )
)

Get the correct result:

vyanjiangmsft_1-1689154534452.png

I attach my sample below for your reference.

 

Best regards,

Community Support Team_yanjiang

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

View solution in original post

8 REPLIES 8
v-yanjiang-msft
Community Support
Community Support

Hi @mmar141 ,

According to your description, here's my solution.

1.Create two tables.

vyanjiangmsft_0-1688955676203.png

vyanjiangmsft_1-1688955718233.png

Sort Date column by Index column, then make relationship between Date table and other tables with Date column.

vyanjiangmsft_2-1688955779044.png

2.Create a measure:

Measure =
SWITCH (
    MAX ( 'Table'[TableName] ),
    "Table1",
        IF (
            MAX ( 'Date'[Date] ) = "%",
            DIVIDE (
                COUNTROWS ( FILTER ( ALL ( 'Table1' ), 'Table1'[Calculated Pass/Fail] = "P" ) ),
                COUNTROWS (
                    FILTER ( ALL ( 'Table1' ), 'Table1'[Calculated Pass/Fail] <> BLANK () )
                )
            ),
            MAX ( 'Table1'[Calculated Pass/Fail] )
        ),
    "Table2",
        IF (
            MAX ( 'Date'[Date] ) = "%",
            DIVIDE (
                COUNTROWS ( FILTER ( ALL ( 'Table2' ), 'Table2'[Calculated Pass/Fail] = "P" ) ),
                COUNTROWS (
                    FILTER ( ALL ( 'Table2' ), 'Table2'[Calculated Pass/Fail] <> BLANK () )
                )
            ),
            MAX ( 'Table2'[Calculated Pass/Fail] )
        ),
    "Table3",
        IF (
            MAX ( 'Date'[Date] ) = "%",
            DIVIDE (
                COUNTROWS ( FILTER ( ALL ( 'Table3' ), 'Table3'[Calculated Pass/Fail] = "P" ) ),
                COUNTROWS (
                    FILTER ( ALL ( 'Table3' ), 'Table3'[Calculated Pass/Fail] <> BLANK () )
                )
            ),
            MAX ( 'Table3'[Calculated Pass/Fail] )
        )
)

In a matrix, put TableName in Rows, Date in Columns and measure in Values, get the correct result:

vyanjiangmsft_3-1688955918094.png

I attach my sample below for your reference.

 

Best regards,

Community Support Team_yanjiang

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

I'm close, but when I add the measure it just displays P?

mmar141_2-1689029288890.pngmmar141_3-1689029338558.pngmmar141_4-1689029407288.png

 

Hi @mmar141 ,

Please check if the Date columns are all in the same data type. I guess some is text and others are date.

 

Best regards,

Community Support Team_yanjiang

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

The data type for my type was indeed text.  However, I cant change the data type column to Text because I added a percentage in one of the rows.  How would I resolve this?  Also, my real report also does not include a %?  How do i add a percentage row to a query that I load from SQL?

Hi @mmar141 ,

If you mean the data type in Table1, Table2 and Table3 is Date, but in the new created table is text, here's my solution.

1.Delete the relationships betwen the four tables.

vyanjiangmsft_0-1689154390775.png

2.Modify the measure to:

Measure =
SWITCH (
    MAX ( 'Table'[TableName] ),
    "Table1",
        IF (
            MAX ( 'Date'[Date] ) = "%",
            DIVIDE (
                COUNTROWS ( FILTER ( ALL ( 'Table1' ), 'Table1'[Calculated Pass/Fail] = "P" ) ),
                COUNTROWS (
                    FILTER ( ALL ( 'Table1' ), 'Table1'[Calculated Pass/Fail] <> BLANK () )
                )
            ),
            MAXX (
                FILTER ( 'Table1', 'Table1'[Date] = CONVERT ( MAX ( 'Date'[Date] ), DATETIME ) ),
                'Table1'[Calculated Pass/Fail]
            )
        ),
    "Table2",
        IF (
            MAX ( 'Date'[Date] ) = "%",
            DIVIDE (
                COUNTROWS ( FILTER ( ALL ( 'Table2' ), 'Table2'[Calculated Pass/Fail] = "P" ) ),
                COUNTROWS (
                    FILTER ( ALL ( 'Table2' ), 'Table2'[Calculated Pass/Fail] <> BLANK () )
                )
            ),
            MAXX (
                FILTER ( 'Table2', 'Table2'[Date] = CONVERT ( MAX ( 'Date'[Date] ), DATETIME ) ),
                'Table2'[Calculated Pass/Fail]
            )
        ),
    "Table3",
        IF (
            MAX ( 'Date'[Date] ) = "%",
            DIVIDE (
                COUNTROWS ( FILTER ( ALL ( 'Table3' ), 'Table3'[Calculated Pass/Fail] = "P" ) ),
                COUNTROWS (
                    FILTER ( ALL ( 'Table3' ), 'Table3'[Calculated Pass/Fail] <> BLANK () )
                )
            ),
            MAXX (
                FILTER ( 'Table3', 'Table3'[Date] = CONVERT ( MAX ( 'Date'[Date] ), DATETIME ) ),
                'Table3'[Calculated Pass/Fail]
            )
        )
)

Get the correct result:

vyanjiangmsft_1-1689154534452.png

I attach my sample below for your reference.

 

Best regards,

Community Support Team_yanjiang

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

Thank you so much for this.  I think I learned more from you than I did in the last 2 weeks by myself.  One last question, is it possible to calculate the % without adding % into the date row? 

Hi @mmar141 ,

I'm glad you learned from here, it's my pleasure! I think we can't do that without a custom column, because for the Total value, customization is not supported.

 

Best regards,

Community Support Team_yanjiang

Wow. This is exactly what I need.  BTW, can I use this with a slicer?  So if I use my slice by date, would this this increase or decrease the amount of columns?

 

Also, i had used a Date Table using Bravo for PowerBI, so I'm having some difficulty adding an Index.  What is the best way to add an index if the date isnt shown in the power query view?

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.