5 Replies Latest reply on Feb 7, 2019 8:07 AM by Norbert Maijoor

# Trouble with calculation

Hi, i have a dataset of log files with the following columns: ID, Date Time and others. I want to sum for every ID the number of day/night logs (Day from 6 am to 17 pm and night from 18 pm to 5 am). After that i need to say if the ID result is "Day" or "Night".
Something like this:

Is it possible to do this with Tableau?

• ###### 1. Re: Trouble with calculation

Could you please attach mocked up sample data and illustrate problem and your expectations.

Thanks,

Shin

• ###### 2. Re: Trouble with calculation

This is a screenshot of my dataset, i need to count for every ID Code the number of day logs and the night logs. Then i compare them and if day logs are greater in the new column Result i put "Day", if lower "night".
Something like this for the final result:

• ###### 3. Re: Trouble with calculation

Hi Tommaso

Find my approach as reference below and stored in attache workbook version 10.5 located in the original thread

1. D0. Date Time (Hours)

2. D1. Day/Night: If [D0. Date Time (Hours)]>=#1-1-2019 06:00# and [D0. Date Time (Hours)]<#1-1-2019 17:00# then 'Day' else 'Night' END

3. D2 Day/Night/Day&Night:

If {fixed [ID]:sum(if [D1. Day/Night]='Day' then 1 end)}>{fixed [ID]:sum(if [D1. Day/Night]='Night' then 1 end)}

then 'Day'

elseif {fixed [ID]:sum(if [D1. Day/Night]='Day' then 1 end)}={fixed [ID]:sum(if [D1. Day/Night]='Night' then 1 end)} then 'Day/Night'

else 'Night' END

4. M1. Count: {fixed [ID],[D1. Day/Night]:countd([Date Time])}

5. Drag the required object to the indicated locations

Hope it helps,

Regards,

Norbert

1 of 1 people found this helpful
• ###### 4. Re: Trouble with calculation

Thank you, this is just what i was looking for!

• ###### 5. Re: Trouble with calculation

Hi Tommaso,

You are welcome. Thanks for the "Badges". Much appreciated:)

Regards,

Norbert