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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
vega
Resolver III
Resolver III

Unary Operators

Hello,

 

I have a question regarding building a model with unary operators. I have the following dimension:

 

MetricMetricAbbrevatedAccountNumberOrder
Room RevenueRoomRev105120511
OccupancyOcc 2
ADRADR 3
RevPARRevPAR 4
Rooms SoldRS9105120RS5
Rooms AvailableRA9105120RA6


I am going to have a fact table that has a column AccountNumber and a column Amount. I want to use the Metric as a slicer and have one measure. The measure will be the sum of the Amount column in the fact table. As you can see, three of the metrics do not have an account number. I need it so that when the user slices on Occupancy, the model with use unary operators to divide the sum of Rooms Sold and Rooms Available. Slice on ADR gives you a division of the sum of room revenue and rooms sold. Slice on RevPAR gives you a division of room revenue and rooms available. Slicing on the others just gives you the sum of amounts that correspond to the account number.

 

Does anyone have any tips on how to accomplish this?

1 ACCEPTED SOLUTION
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @vega,

 

Try this demo please. (Many details are in the file.)

Measure =
IF (
    HASONEVALUE ( 'Table1'[Metric] ),
    IF (
        VALUES ( Table1[Metric] ) = "Occupancy",
        DIVIDE (
            CALCULATE (
                SUM ( Table2[Amount] ),
                FILTER (
                    ALL ( Table2 ),
                    'Table2'[AccountNumber] IN { "9105120RS", "9105120RA" }
                ),
                ALL ( Table1 )
            ),
            2,
            0
        ),
        IF (
            VALUES ( Table1[Metric] ) = "ADR",
            DIVIDE (
                CALCULATE (
                    SUM ( Table2[Amount] ),
                    FILTER (
                        ALL ( Table2 ),
                        'Table2'[AccountNumber] IN { "10512051", "9105120RS" }
                    ),
                    ALL ( Table1 )
                ),
                2,
                0
            ),
            IF (
                VALUES ( Table1[Metric] ) = "RevPAR",
                DIVIDE (
                    CALCULATE (
                        SUM ( Table2[Amount] ),
                        FILTER (
                            ALL ( Table2 ),
                            'Table2'[AccountNumber] IN { "10512051", "9105120RA" }
                        ),
                        ALL ( Table1 )
                    ),
                    2,
                    0
                ),
                SUM ( Table2[Amount] )
            )
        )
    ),
    BLANK ()
)

Best Regards,

Dale

Community Support Team _ Dale
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

4 REPLIES 4
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @vega,

 

Try this demo please. (Many details are in the file.)

Measure =
IF (
    HASONEVALUE ( 'Table1'[Metric] ),
    IF (
        VALUES ( Table1[Metric] ) = "Occupancy",
        DIVIDE (
            CALCULATE (
                SUM ( Table2[Amount] ),
                FILTER (
                    ALL ( Table2 ),
                    'Table2'[AccountNumber] IN { "9105120RS", "9105120RA" }
                ),
                ALL ( Table1 )
            ),
            2,
            0
        ),
        IF (
            VALUES ( Table1[Metric] ) = "ADR",
            DIVIDE (
                CALCULATE (
                    SUM ( Table2[Amount] ),
                    FILTER (
                        ALL ( Table2 ),
                        'Table2'[AccountNumber] IN { "10512051", "9105120RS" }
                    ),
                    ALL ( Table1 )
                ),
                2,
                0
            ),
            IF (
                VALUES ( Table1[Metric] ) = "RevPAR",
                DIVIDE (
                    CALCULATE (
                        SUM ( Table2[Amount] ),
                        FILTER (
                            ALL ( Table2 ),
                            'Table2'[AccountNumber] IN { "10512051", "9105120RA" }
                        ),
                        ALL ( Table1 )
                    ),
                    2,
                    0
                ),
                SUM ( Table2[Amount] )
            )
        )
    ),
    BLANK ()
)

Best Regards,

Dale

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

This gets the job done with some tweaking. Question for you, can you explain why the ALL(Table1 is needed as a filter for the calculate sum?

Hi @vega,

 

The ALL(Table1) removes the filters from Table1.

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
parry2k
Super User
Super User

yes all this can be done, if you share sample data from both of your tables, will help to provide the solution.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

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.