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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
wasirafi
Helper I
Helper I

DAX Error when using If Statement with DateAdd

https://1drv.ms/u/s!AjIGh95acxebg6JDCZEPNu4K7yIYQg?e=i1Vuqa  - PBIX File

 

Hi PB Community

 

i am trying to use If statement in my DAX expression as below

new date1 = IF('bi v_shift'[shiftName] = "night" && 'bi v_shift'[startOffsetMinutes] > 55, DATEADD('bi v_shift'[dateTimeNearestHour],-1,DAY),'bi v_shift'[dateTimeNearestHour]).
 
I get the below error
"A single value for column 'dateTimeNearestHour' in table 'bi v_shift' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count"
 
All i want is if Shift name is "night" and StartOffsetMinutes is greater than 55 minutes, then the Date in Datetimenearesthour should go back by 1 day.
 
FYI Datetimenearesthour is Date/time type, i changed it to DAte time still getting errors.
I am fine with Either Column or Measure
1 ACCEPTED SOLUTION

pls try this

Column = IF(
        'bi v_shift'[shiftName]= "night"&& 
        'bi v_shift'[startOffsetMinutes]>55,
        'bi v_shift'[dateTimeNearestHour].[Date]-1,
        'bi v_shift'[dateTimeNearestHour].[Date]
        )

Screenshot_2.png

View solution in original post

11 REPLIES 11
Ahmedx
Super User
Super User

replace the following expression
DATEADD('bi v_shift'[dateTimeNearestHour],-1,DAY)
with
bi v_shift'[dateTimeNearestHour]-1

still the same error

wasirafi_0-1705763280148.png

 

remove these ( )
I also advise you to give columns and tables a normal name without spaces or hyphens.

Screenshot_1.png

Ahmed,

I only removed "()" not the content inside it, as that is the second IF criteria.

I did note your point on not having Spaces and Hypen in the name of the table. The Dataset is owned by 3rd party and i cannot influence that.

 

The error still remains

 

wasirafi_0-1705763967472.png

 

 

Is this columns in this table or in another?

i just attached the PBIX file....if that helps

https://1drv.ms/u/s!AjIGh95acxebg6JDCZEPNu4K7yIYQg?e=i1Vuqa 

pls try this

Column = IF(
        'bi v_shift'[shiftName]= "night"&& 
        'bi v_shift'[startOffsetMinutes]>55,
        'bi v_shift'[dateTimeNearestHour].[Date]-1,
        'bi v_shift'[dateTimeNearestHour].[Date]
        )

Screenshot_2.png

Thanks @Ahmedx  You were very helpful

All the columns are from the same Table.

speedramps
Super User
Super User

We want to help you but your description is too vaugue. Please write it again clearly.

Please DON'T copy & paste your DAX that does not work and expect us to fathom what you want to do. That is a bit crazy. 😀

Please just give a simple non technical functional decscription of what you want, then let us suggest the solution. Thank you.

Provide example input data as table text (not a screen print) so we can import the data to build a solution for you.
Also provide the example desired output, with a clear description of the process flow.
Remember not to share private data ... we don't want you to get into trouble. 😧
Take time and care to use the same table and field names in the input, output and description so we can understand your problem and help you.
Try keep it simple and ask one question per ticket.
You will get a quick response if you put time, care and effort into writing clear problem descriptions.

Vaugue descriptions can waste your time and ourtime.

Look foward to helping you when the above information is forthcoming

Attached spreadsheet!!

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

Find out what's new and trending in the Fabric Community.