Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

Advanced IF function

Hello,

 

I am pretty new in Power BI and I am trying to figure out how can I do my task. I need to write a dax (probably by function IF) where when day of the month is less or equal to 5, I need to add to my price  4% costs, for these 5 days of new month and all previous month. But when day of the month passes 6 and more, I need add to the price 4% only for this new month. No more previous month.

Example: If now is second day of new month, I need + 4% to my price for this new month (2 days) and all days of previous month. If now is 6th day of the new month, I need + 4% to my price only for this month and no more for previous month. 
Can someone help me please? 

This is one of my many attempts, but this is not working properly. 

Probably, because my condition "|| lastmonth" is everytime fullfiled.
Thanks for your advices

3 Replies

  • v-yadongf-msft's avatar
    v-yadongf-msft
    Community Support

    Hi Anonymous ,

     

    Please try following DAX:

    Cost = SWITCH(
        TRUE(),
        MAXX(FILTER('Table','Table'[Month] = MONTH(TODAY())),'Table'[Day])<=5,[VNC+ Import]*1.04,
        'Table'[Month] = MONTH(TODAY()) && MAXX(FILTER('Table','Table1'[Month] = MONTH(TODAY())),'Table'[Day])>6,[VNC+ Import]*1.04
        )

     

    I did test in two tables and both worked.

     

    Test table 1, until Oct 7th:

     

    Test table 2, until Oct 3rd:

     

    Best regards,

    Yadong Fang

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

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello,

      unfortunately, it is not working for me and I do not know why. I tied exactly what you suggested, but no matter what, it is still multypling only this month and all data from previous months just disappear, which is not good. Even when I tied lower numbers of day, it still multiplied only this new month, never last month. 

  • v-yadongf-msft's avatar
    v-yadongf-msft
    Community Support

    Hi Anonymous ,

     

    It's so strange!

    Can you share with me some sample data in table like this?

     

    Best regards,

    Yadong Fang