Forum Discussion

TonyGu's avatar
TonyGu
Helper I
4 years ago
Solved

DAX Column

I would like to have the Define column return 1, if ID only appear 1 time in that year. If that ID appear twice or more, return 1 for the earliest Month, and 0 for the rest month. Below is the result I want to get. Not sure if it is doable.

 

 

 

 

  • You can just check if the month is the first one that year or not.

     

    Try this as a calculated column:

    Define =
    VAR _FirstMonth =
        CALCULATE (
            MIN ( Table1[MONTH] ),
            ALLEXCEPT ( Table1, Table1[ID], Table1[YEAR] )
        )
    RETURN
        IF ( Table1[MONTH] = _FirstMonth, 1, 0 )
    

5 Replies

  • You can just check if the month is the first one that year or not.

     

    Try this as a calculated column:

    Define =
    VAR _FirstMonth =
        CALCULATE (
            MIN ( Table1[MONTH] ),
            ALLEXCEPT ( Table1, Table1[ID], Table1[YEAR] )
        )
    RETURN
        IF ( Table1[MONTH] = _FirstMonth, 1, 0 )
    
  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    TonyGu Maybe:

    Define =
      VAR __ID = [ID]
      VAR __Year = [Year]
      VAR __Month = [Month]
      VAR __MinMonth = MINX(FILTER('Table',[ID] = __ID && [Year] = __Year),[Month])
      VAR __Table = SUMMARIZECOLUMNS('Table'[ID],'Table'[Year],"__Count",COUNTROWS('Table'))
    RETURN
      SWITCH(TRUE(),
        COUNTROWS(FILTER(__Table,[ID] = __ID && [Year] = __Year)) = 1,1,
        __Month = __MinMonth, 1,
        0
      )
  • Hello:

    Give this a try. Hope it helps..

     

    Define =
    var yr = Data[Year]
    var countinyear = COUNTROWS(
    FILTER(Data, Data[Year] = yr))
    return
    IF(countinyear = 1 || Data[Mo] = 1,1,0)
    • AlexisOlson's avatar
      AlexisOlson
      Super User

      You seem to be assuming that January is always the first month for each year with multiple rows in the Data table (e.g. this would not work if the first D row in the given example were deleted).

  • v-xiaotang's avatar
    v-xiaotang
    Community Support

    Hi TonyGu 

    Have you solved this question with the help of enthusiastic users? If you have solved the question, you can accept the answer helpful as the solution or share you method and accept it as solution, thanks for your contribution to improve Power BI.

    If you need more help, please let me know.

     

    Best Regards,

    Community Support Team _Tang

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