Forum Discussion

rokas147's avatar
rokas147
Frequent Visitor
5 years ago

If statement with year

Hi all,

 

this is the problem I am facing. I have 3 years, 2018, 2019 and 2020. 

The formula I am using:

 

Case study calculated = IF('2018-2019-2020_data'[Year]="2020",(SUM('2018-2019-2020_data'[Case studies])/0.67*'Case Study discount'[Case Study discount Value]/100), SUM('2018-2019-2020_data'[Case studies]) )
P.s. when writing this formula I get an error stating: a single value for column "Year" cannot be determined. 
 
Case study discount value = is a value in the slicer.
 
My goal is, to have case study calculated WITH the slicer value for the year 2020, in other years 2018 and 2019, I just want the value of case studies. 
 
Currently, as I cannot implement this function the slicer for case studies affects all year, but it should only affect year 2020.
 
My year column only contains values such as 2018, 2019 or 2020.
 
Any help would be highly appreciated.
 
Cheers

7 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

     Why not create a calculated column in your table ?

    CaseStudiesCalculated = 

    IF('2018-2019-2020_data'[Year]="2020",'2018-2019-2020_data'[Case studies])/0.67*'Case Study discount'[Case Study discount Value]/100),SUM('2018-2019-2020_data'[Case studies])

     

    Then show the SUM of column in your visual

    • rokas147's avatar
      rokas147
      Frequent Visitor

      The problem is I cannot select '2018-2019-2020_data'[Year], thus the question is maybe I should be accessing this data somewhat different, I have tried uploading it as a string and as a numeric value. It didn't work both times 

    • rokas147's avatar
      rokas147
      Frequent Visitor

      Thats the problem, when try using IF statement, it does not detect my "Year Column", therefore, it doesnt work

  • Anonymous's avatar
    Anonymous
    Not applicable

    Show an example

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi rokas147 

    Do you want to build a calculated column or a measure?

    If you want to build a measure, use max function to get the Year value in '2018-2019-2020_data'.

    If you want to build a calculated column, you use values from different tables. In which table do you want to build this calculated table, 'Case Study discount' or '2018-2019-2020_data'. If you want to build a calculated column in 'Case Study discount', you can't use Case studies and Year in '2018-2019-2020_data' directly, try to use related function to get the value.

    You may refer to this blog for more details: Dax Error

    If this reply still couldn't help you solve your problem, please share a sample with me by your Onedrive for Business.

    And show a the result you want by screenshot. This will make it easier for me to understand your requirement.

     

    Best Regards,

    Rico Zhou

     

    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

    Hi rokas147 

    Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file from your Onedrive for Business.

     

    Best Regards,

    Rico Zhou

  • rokas147's avatar
    rokas147
    Frequent Visitor

    Lol, i just had to create a column instead of a measure, my faultsies boys and girls, apologize