Reply
ljx0648
Helper III
Helper III
Partially syndicated - Outbound

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

Syndicated - Outbound

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

Syndicated - Outbound

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

Syndicated - Outbound

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

 

avatar user

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)