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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
ljx0648
Helper II
Helper II

create a calculated measure or column based on different conditions

Hi guys,

 

Below is the data I have:

CustomerCount of Plan PurchasedTypeFrequencyDescriptionAmount
A1Weekly1Pay every 1 week10
B2Weekly2Pay every 2 week10
C3Monthly1Pay every 1 month10
D4Monthly12Pay every 12 month10

 

My goal here is calculate the Monthly average paymen of each customer.

 

The logic I am trying to implement is that 

 

When Type = Weekly and Frequency is 1 (pay every week), then the monthly amount should be = Amount * count of plan purchased * 4 (becauie there are 4 weeks in a month)

 

When Type = Weekly and Frequency is 2 (pay every 2 week), then the monthly amount should be = Amount * count of plan purchased * 2 (becauie there are 2* 2 weeks in a month)

 

Whenn Type = Monthly and Frequency is 1, then the monthly amount should be = Amount * count of plan purchased * 1

 

Whenn Type = Monthly and Frequency > 1, then the monthly amount should be = Amount * count of plan purchased divided frequncy (in the example here the frequency is 12, however, there are 2,3,4 etc in the real data)

 

May I know if anyone have an idea how to write such logic in a calculated column OR measure?

 

Thank you

 

 

1 ACCEPTED SOLUTION
v-yilong-msft
Community Support
Community Support

Hi @ljx0648 ,

I create a table as you mentioned.

vyilongmsft_0-1718587720892.png

Then I create a calculated column and here is the DAX code.

Column = 
SWITCH (
    TRUE (),
    'Table'[Type] = "Weekly"
        && 'Table'[Frequency] = 1,
        'Table'[Amount] * 'Table'[Count of Plan Purchased] * 4,
    'Table'[Type] = "Weekly"
        && 'Table'[Frequency] = 2,
        'Table'[Amount] * 'Table'[Count of Plan Purchased] * 2,
    'Table'[Type] = "Monthly"
        && 'Table'[Frequency] = 1,
        'Table'[Amount] * 'Table'[Count of Plan Purchased] * 1,
    'Table'[Type] = "Monthly"
        && 'Table'[Frequency] > 1,
        'Table'[Amount] * 'Table'[Count of Plan Purchased] / 'Table'[Frequency],
    BLANK ()
)

Finally you will get what you want.

vyilongmsft_1-1718587936911.png

 

 

 

Best Regards

Yilong Zhou

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

2 REPLIES 2
v-yilong-msft
Community Support
Community Support

Hi @ljx0648 ,

I create a table as you mentioned.

vyilongmsft_0-1718587720892.png

Then I create a calculated column and here is the DAX code.

Column = 
SWITCH (
    TRUE (),
    'Table'[Type] = "Weekly"
        && 'Table'[Frequency] = 1,
        'Table'[Amount] * 'Table'[Count of Plan Purchased] * 4,
    'Table'[Type] = "Weekly"
        && 'Table'[Frequency] = 2,
        'Table'[Amount] * 'Table'[Count of Plan Purchased] * 2,
    'Table'[Type] = "Monthly"
        && 'Table'[Frequency] = 1,
        'Table'[Amount] * 'Table'[Count of Plan Purchased] * 1,
    'Table'[Type] = "Monthly"
        && 'Table'[Frequency] > 1,
        'Table'[Amount] * 'Table'[Count of Plan Purchased] / 'Table'[Frequency],
    BLANK ()
)

Finally you will get what you want.

vyilongmsft_1-1718587936911.png

 

 

 

Best Regards

Yilong Zhou

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

djurecicK2
Super User
Super User

Hi @ljx0648 ,

 You could look into using a SWITCH function to achieve this in a measure.

 

https://learn.microsoft.com/en-us/dax/switch-function-dax

 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors