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

Get Fabric certified for FREE! Don't miss your chance! Learn more

Reply
rollingzep
Regular Visitor

Date calculation

Hi,

 

I have two dates in col A, report date and col B, Transaction Date.  I need to populate a new column, C.

The condition is,  insert value 1 in Col C if Transaction Date is less than or equal to 30 days of report date or 

insert value 1 in Col C if Transaction Date is null.

 

I know how to do it in Excel VBA but I am new to Power BI.  In VBA, I use

If DateDiff("d", FirstDate, SecondDate) <= 30 Then ws.Range("C" & i) = 1, for the first condition.

Not sure how to create a new Measure using Datediff.

Also, I loop through the entire range as in LastRow = ws.Range("B" & Rows.Count).End(xlUp).Row).

what is the equivalent in BI?

 

TIA

 

 

 

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@rollingzep Try:

Column C = 
  SWITCH(TRUE(),
    [Transaction Date] = BLANK(), 1,
    ( [Report Date] - [Transaction Date] ) * 1. <= 30, 1,
    BLANK()
  )


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

View solution in original post

4 REPLIES 4
Greg_Deckler
Community Champion
Community Champion

@rollingzep Try:

Column C = 
  SWITCH(TRUE(),
    [Transaction Date] = BLANK(), 1,
    ( [Report Date] - [Transaction Date] ) * 1. <= 30, 1,
    BLANK()
  )


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

I am getting an error

 

rollingzep_0-1677176038662.png

I do have asofdate and TransactionEndDate and I am trying to create a new Measure.

 

@rollingzep If it's a measure then you need to wrap your column references in something like MAX or MIN.

Measure C = 
  SWITCH(TRUE(),
    MAX([Transaction Date]) = BLANK(), 1,
    ( MAX([Report Date]) - MAX([Transaction Date]) ) * 1. <= 30, 1,
    BLANK()
  )


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

Still getting this error

 

"Column 'asofdate' cannot be found or may not be used in this expression". is this because another table has the the same field, asofdate? If so, how to qualify using tablename in the Expression? or is it because of the date format?

Helpful resources

Announcements
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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