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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
ljx0648
Helper III
Helper III

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
Anonymous
Not applicable

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
Anonymous
Not applicable

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
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors