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
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
Employee
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
Employee
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
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.