Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Macro in expression

Hi,

I made a macro to calculate the delay working days between two dates and I'd like to use it inside a chart expression...something like that:

Sum(If(ArrivalData>=DueDate,GetWorkDays (ArrivalDate, DueDate),0))/Count(NumberOfDocuments)

But the expression give me a syntax error, maybe due to the use of the macro into the expression...is that true? Is there a workaround for the problem?

Thanks.

N.

5 Replies
alexandros17
Partner - Champion III
Partner - Champion III

You can define a variable in which you repeat the logic of your macro, then use variable in expression

Anonymous
Not applicable
Author

I did not understand the purpose to create a macro in such situation. Normally, either we create variable, or a temporary column .

If you must do something like this in chart, then you can create expressions in the chart,

first expression:

ArrivalData-DueDate

Secondexpression: Sum(If(column(1)>0, GetWorkDays (ArrivalDate, DueDate),0))/Count(NumberOfDocuments)

Something like this should help

Anonymous
Not applicable
Author

Well, the macro is this:

Function GetWorkDays(StartDate, EndDate)

    dCount = 0

    For dt = StartDate To EndDate

        If WeekDay(dt) <> 1 Then

            dCount = dCount + 1

        End If

    Next

    GetWorkDays = dCount

End Function

Should someone explain to me how can I transform it in a varialble?

Thks

N.

alexandros17
Partner - Champion III
Partner - Champion III

Probably you need networkingdate() function instead of the variable

Anonymous
Not applicable
Author

The NetWorkDays() Function considers the work days from Mon to Fri, contrariwise I've to consider Sat as a workable day.

This is the reason I've made the macro.

Thks.