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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
sam_gift
Helper I
Helper I

Create rows based on existing rows for a dimension of a visual

I am new in Power BI. I have the below requirement. There are 2 tables: 1 fact and 1 dimension.

Fact Table:

Currencyrep_item_id
21
21
41
51
62
222
853
673
283


Dimension Table:

rep_item_idDescription
1KF001
2KF002
3KF003
4KF004
5KF005
6KF006

 

I have to create measures for

KF004=KF003/KF002 i.e., (sum of currencies of rep_item_id=3)/(sum of currencies of rep_item_id =2)
KF005=KF001*KF002 i.e., (sum of currencies of rep_item_id=1) multiplied with (sum of currencies of rep_item_id =2)
KF006= if KF003>0 then 1-(KF003/KF001) else 0.i.e., if sum of currencies of rep_item_id is greater than 0, then (1 - (sum of currencies of rep_item_id=3)/(sum of currencies of rep_item_id =1) else 0.
Power BI Visual for report:

KF00113
KF00228
KF003180
KF0046.428571
KF005364
KF006

-12.8462

 

This is the sample dataset. Please need assistance of how to implement this. The source is SAP. we are trying to move the reports from SAC Model to Power BI

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

HI @sam_gift,

You can try to use the following measure formula to use the current description as conditions to redirect to different calculation expressions:

formula = 
VAR currDesc =
    SELECTEDVALUE ( 'Dimension'[Description] )
VAR kf1 =
    CALCULATE (
        SUM ( 'Fact'[Currency] ),
        FILTER ( ALLSELECTED ( 'Fact' ), 'Fact'[rep_item_id] = 1 )
    )
VAR kf2 =
    CALCULATE (
        SUM ( 'Fact'[Currency] ),
        FILTER ( ALLSELECTED ( 'Fact' ), 'Fact'[rep_item_id] = 2 )
    )
VAR kf3 =
    CALCULATE (
        SUM ( 'Fact'[Currency] ),
        FILTER ( ALLSELECTED ( 'Fact' ), 'Fact'[rep_item_id] = 3 )
    )
VAR kf4 = kf3 / kf2
VAR kf5 = kf1 * kf2
VAR kf6 =
    IF ( kf3 > 0, 1 - kf3 / kf1, 0 )
VAR _current =
    CALCULATE (
        SUM ( 'Fact'[Currency] ),
        FILTER (
            ALLSELECTED ( 'Fact' ),
            [rep_item_id] IN VALUES ( 'Dimension'[rep_item_id] )
        )
    )
RETURN
    SWITCH ( currDesc, "KF004", kf4, "KF005", kf5, "KF006", kf6, _current )

Regards,

Xiaoxin Sheng

View solution in original post

1 REPLY 1
Anonymous
Not applicable

HI @sam_gift,

You can try to use the following measure formula to use the current description as conditions to redirect to different calculation expressions:

formula = 
VAR currDesc =
    SELECTEDVALUE ( 'Dimension'[Description] )
VAR kf1 =
    CALCULATE (
        SUM ( 'Fact'[Currency] ),
        FILTER ( ALLSELECTED ( 'Fact' ), 'Fact'[rep_item_id] = 1 )
    )
VAR kf2 =
    CALCULATE (
        SUM ( 'Fact'[Currency] ),
        FILTER ( ALLSELECTED ( 'Fact' ), 'Fact'[rep_item_id] = 2 )
    )
VAR kf3 =
    CALCULATE (
        SUM ( 'Fact'[Currency] ),
        FILTER ( ALLSELECTED ( 'Fact' ), 'Fact'[rep_item_id] = 3 )
    )
VAR kf4 = kf3 / kf2
VAR kf5 = kf1 * kf2
VAR kf6 =
    IF ( kf3 > 0, 1 - kf3 / kf1, 0 )
VAR _current =
    CALCULATE (
        SUM ( 'Fact'[Currency] ),
        FILTER (
            ALLSELECTED ( 'Fact' ),
            [rep_item_id] IN VALUES ( 'Dimension'[rep_item_id] )
        )
    )
RETURN
    SWITCH ( currDesc, "KF004", kf4, "KF005", kf5, "KF006", kf6, _current )

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.