Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
wdchristensen
Specialist
Specialist

Modulo chart function (Qlik Sense 3.2)

Good Morning Everyone,

I am trying to figure out why my mod function isn't working as I expected.

=Interval(Now(0)-Packing_DtTm,'DD')

The above line gives me the number of days and works fine.

=mod(Interval(Now(1)-Packing_DtTm, 'mm'), 1440)

The above line is supposed to produce the number of minutes without the day portion since that is included in the day calculation.

https://help.qlik.com/en-US/sense/September2017/Subsystems/Hub/Content/ChartFunctions/GeneralNumeric...

I am not sure what I am missing. I checked Packing_DtTm with isnum and it appears to be a real date. Any help you can provide would be greatly appreciated!

1 Solution

Accepted Solutions
sunny_talwar

May be this

=Interval(frac(Now(1)-Today()), 'mm')

View solution in original post

6 Replies
wdchristensen
Specialist
Specialist
Author

Below is an example that also doesn't work but doesn't rely on any specific data.

=mod(Interval(Now(1)-Today(), 'mm'),60)

sunny_talwar

May be this

=Interval(frac(Now(1)-Today()), 'mm')

marcus_sommer

The reason because mod() didn't work is that the function accepts only integers as parameter. Beside this I doubt that mod() will return what do you want. Therefore go just with the suggestion from Sunny or calculate your wished output directly maybe with something like:

floor((Now(2)-Packing_DtTm) / 24 / 60)

- Marcus

wdchristensen
Specialist
Specialist
Author

stalwar1,


Your solution is great! However I am struggling to understand why I can't get mod to work.


https://help.qlik.com/en-US/sense/September2017/Subsystems/Hub/Content/Scripting/FormattingFunctions...


marcus_sommer

You were total right about mod needing integers and the interval function returns a dual. With some tweaking I was able to get it to work as I originally expected.


So my original formula can be modified as follows to works as expected but is far less elegant!

=mod(Num#(Text(Interval(Now(1)-Today(), 'mm'))), 60)

Great learning lesson! Thanks

sunny_talwar

Are the two expressions really equal?

mod(Num#(Text(Interval(Now(1)-Today(), 'mm'))), 60)

Interval(frac(Now(1)-Today()+1), 'mm')


Capture.PNG

1st one is telling me that it has been 12 minutes into the hour, but the second one is saying that it has been 672 minutes into the day... what exactly are you trying to calculate? It seemed as if you wanted to calculate minutes into the day.... but this might have been about modulo... but either ways... there might be multiple other ways to handle this... but even before going into modulo... think about the fact that hours and minutes are really fractions and modulo with 1440 might not really be the right way to go... unless you use Num#() function... like you did...

wdchristensen
Specialist
Specialist
Author

As you might have guessed my real application is a bit different than the question but I was really trying to understand the syntax. Good catch on my typo. It was supposed to be 1440.

=mod(Num#(Text(Interval(Now(1)-Today(), 'mm'))), 1440)

=Interval(frac(Now(1)-Today()+1), 'mm')

=Minute(Time(Now(1)))+(Hour(Time(Now(1)))*60)