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
TonyGu
Helper I
Helper I

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.

 

TonyGu_2-1645130011606.png

 

 

 

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

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 )

View solution in original post

5 REPLIES 5
v-xiaotang
Community Support
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.

Whitewater100
Solution Sage
Solution Sage

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)

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).

AlexisOlson
Super User
Super User

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
Community Champion
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
  )


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 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.