Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
adaxx
New Member

Need help on this DAX error message

My logic is this: 

If variable date2 is not blank for this each ID, then output date2.

If date2 is blank, then output a random number between 0 and the most recent month of column date1.

 

So the sample data is like this:

IDdate1date2output
12023-02-2833
22023-05-31 5
32022-12-3100
42023-04-3011
52023-01-3144
62023-03-31 5

 

This is my function:

MO = IF(ISBLANK('table'[Date1])=False,'table'[Date1],RANDBETWEEN(0,(max(month('table'[date2]))))), but it keeps giving me error: The MAX function only accepts a column reference as an argument.
 
Can someone help me with this? Thank you!!!
2 REPLIES 2
danextian
Super User
Super User

Hi @adaxx ,

 

MAX function accepts either a column

=
MAX ( table[column] )


or two scalar  values

=
MAX ( 1, 2 )
=
MAX ( MONTH ( table[date column] ), 100 )

This part of your formula retuns just ONE scalar value

=
MONTH ( 'table'[date2] )

Below is your formula modified so the syntax is correct but I am not sure what you are trying to achieve here. You also did not mention if it is a measure or a calc column

MO =
IF (
    ISBLANK ( 'table'[Date1] ) = FALSE,
    'table'[Date1],
    RANDBETWEEN ( 0, MONTH ( 'table'[date2] ) )
)

danextian_0-1687998639388.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
v_mark
Helper V
Helper V

Try this. You might need to tweak the calculated column measure a little bit to tailor fit your needs. 

Output Measure =
IF(
    NOT(ISBLANK('Table'[date2])),
    'Table'[date2],
    RAND() * EOMONTH(MAX('Table'[date1]), 0)
)

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors