6 Replies Latest reply: Apr 5, 2018 11:26 AM by William Christensen

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/GeneralNumericFunctions/mod.htm

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!

• Re: Modulo chart function (Qlik Sense 3.2)

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

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

• Re: Modulo chart function (Qlik Sense 3.2)

May be this

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

• Re: Modulo chart function (Qlik Sense 3.2)

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

• Re: Modulo chart function (Qlik Sense 3.2)

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

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

• Re: Modulo chart function (Qlik Sense 3.2)

Are the two expressions really equal?

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

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

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

• Re: Modulo chart function (Qlik Sense 3.2)

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)