Current Month Without Using Selection - QlikView Set Analysis - qlikview

I am stuck with some mysterious issue while trying to get Revenue for Current Month.
My Limitation is Simple :
I need Current Month Revenue Without Having to do any selections.
So here are the details :
Data_Date field has two values one for Dec, and one for Nov 2016
11/15/2016
12/15/2016
I have declared a variable vCurrent_Month
=Date#( Max(Data_Date))
Value in Variable is correctly Reflecting 12/15/2016
Given below is my Set Analysis Expression used in Text Object:
=Sum({1<Date#(Data_Date)={"(vCurrent_Month)"}>}TOTAL_REVENUE)
I am getting following error
Error: Error in set modifier expression
I have been stuck for hours and I have tried several tutorials and ways to get the same result but there seems to be no way out. Any help is highly appreciated.
Thanks

Try this:
=Sum({1<Data_Date={'$(vCurrent_Month)'}>}TOTAL_REVENUE)
Trying to do the number formatting in the first part of the set analysis is what is causing the error message you're getting.
After that to get it to work you need to make these changes:
You left out the $() expansion then the variable won't evaluate and you used double quotes which will return a field name rather than a value

Related

Argument type mismatch error using the DaysBetween() function in a calculated measure

I am using icCube 5.0.1 and in the process of upgrading to 5.1.
I am attempting to use the Builder to create a Calculated Measure using the following formula: DaysBetween([LastReportingDate], Today())
[Measure].[LastReportingDate] is a measure within the cube with a Date data type.
The purpose is to create a calculated measure that provides the number of days between [Measure].[LastReportingDate] and today and use it within a report.
When I add the new calculated measure to a report table, the column cells are filled with 'error', and when I hover over a cell the error message reads: DaysBetween(): argument (0) type mismatch: expected 'date' got: 'measure'.
Manual reference: http://www.iccube.com/support/documentation/mdx/DaysBetween.php
Any hints? Many thanks!
Can you use the memberValue property:
DaysBetween([LastReportingDate].MemberValue, Today())
(p.s. I use Pyramid not icCube so this may be way of the mark!)
Assuming the [LastReportingDate] is a time dimension (i.e., with the member key being an actual date (and not a string representing a date) ) you can do the following:
DaysBetween( [LastReportingDate].KEY, Today() )
In case [LastReportingDate] is a [Measures] of type Date, you can use the Value() function to get its actual date as following:
DaysBetween( [Measures].[LastReportingDate].Value, Today() )
Note: If the key is a string, please edit your question with its pattern description.
After more research and experimentation, I solved the problem as follows:
I used the following formula for the calculated variable: Today()-[LastReportingDate]
I used the following Cell Properties entry: Format_String = '#,##0' Note that without using the the Format_String, the report displayed a date.
Thanks to all for your assistance.

How to display comparisons with set expression?

My dataset has WeekEndingDate and Sales. I am displaying a straight table with all the selected data but I need to have another table showing the following:
Sales (other columns...)
First week : 1,000
Last week : 1,350
Difference : 350
Difference %: 35%
My questions:
a) Can I have the above in one chart/table, or I need 4 different charts showing columns filtered by set expressions?
b) My strategy is having 2 variables (vMinWeek and vMaxWeek), and using them in set expressions. Is that the best route?
c) My set expressions (below) are not working - they sum the whole data set. Would you please help me understanding why?
=max ({$<WeekEndingDate={'$(vMinWeek)'}>} Sales)
Thank you for your help!
Mara
I think the reason your set isn't working is that your WeekEnd date is formatted as a date and your variable is formatted as a number.
The trick with Set Analysis is always to think what you would have to type in a list box to get to your answer. So even though QlikView stores WeekEnd 2014/08/18 as 41869 you can't type 41869 in the WeekEnd list box and get back that date. So I would make your variables of the form =date(min(WeekEnd)).
The second part of your question; getting the table you want. I would do like this. I make a loose table with the dimension values, dual is so that it sorts correctly in the chart we are going to build.
load dual(D,N) as DIM inline [
D,N
First Week,1
Last Week,2
Difference,3
Dif %,4
];
I like defining my variables in the script as well, so I would do this.
set vFirstWeek='=date(min(WeekEnd))';
set vLastWeek='=date(max(WeekEnd))';`
Then when building the straight table we use the dimension as DIM but because DIM isn't connected to anything we have to do some work to get it to display values that fit those dimension values. The num(,'# ##0') is just to format the % differently from the sums. For this to work the number format in the Number tab of the chart must be set to Expression Default.
if(DIM='First Week',num(sum({<WeekEnd={'$(vFirstWeek)'}>} Sales),'# ##0'),
if(DIM='Last Week',num(sum({<WeekEnd={'$(vLastWeek)'}>} Sales),'# ##0'),
if(DIM='Difference',num(sum({<WeekEnd={'$(vFirstWeek)'}>} Sales)-sum({<WeekEnd={'$(vLastWeek)'}>} Sales),'# ##0'),
if(DIM='Dif %',num((sum({<WeekEnd={'$(vFirstWeek)'}>} Sales)-sum({<WeekEnd={'$(vLastWeek)'}>} Sales))/sum({<WeekEnd={'$(vLastWeek)'}>} Sales),'0.00%')))))

Enter date into function without quotes, return date

I'm trying to write a function of this form:
Function cont(requestdate As Date)
cont = requestdate
End Function
Unfortunately, when I enter =cont(12/12/2012) into a cell, I do not get my date back. I get a very small number, which I think equals 12 divided by 12 divided by 2012. How can I get this to give me back the date? I do not want the user to have to enter =cont("12/12/2012").
I've attempted to google for an answer, unfortunately, I have not found anything helpful. Please let me know if my vocabulary is correct.
Let's say my user pulled a report with 3 columns, a, b and c. a has beginning of quarter balances, b has end of quarter balances and c has a first and last name. I want my user to put in column d: =cont(a1,b1,c1,12/12/2012) and make it create something like:
BOQ IS 1200, EOQ IS 1300, NAME IS EDDARD STARK, DATE IS 12/12/2012
So we could load this into a database. I apologize for the lack of info the first time around. To be honest, this function wouldn't save me a ton of time. I'm just trying to learn VBA, and thought this would be a good exercise... Then I got stuck.
Hard to tell what you are really trying to accomplish.
Function cont(requestdate As String) As String
cont = Format(Replace(requestdate, ".", "/"), "'mm_dd_YYYY")
End Function
This code will take a string that Excel does not recognize as a number e.g. 12.12.12 and formats it (about the only useful thing I can think of for this UDF) and return it as a string (that is not a number or date) to a cell that is formatted as text.
You can get as fancy as you like in processing the string entered and formatting the string returned - just that BOTH can never be a number or a date (or anything else Excel recognizes.)
There is no way to do exactly what you're trying to do. I will try to explain why.
You might think that because your function requires a Date argument, that this somehow forces or should force that 12/12/2012 to be treated as a Date. And it is treated as a Date — but only after it's evaluated (only if the evaluated expression cannot be interpreted as a Date, then you will get an error).
Why does Excel evaluate this before the function receives it?
Without requiring string qualifiers, how could the application possibly know what type of data you intended, or whether you intended for that to be evaluated? It could not possibly know, so there would be chaos.
Perhaps this is best illustrated by example. Using your function:
=Cont(1/1/0000) should raise an error.
Or consider a very simple formula:
=1/2
Should this formula return .5 (double) or January 2 (date) or should it return "1/2" (string literal)? Ultimately, it has to do one of these, and do that one thing consistently, and the one thing that Excel will do in this case is to evaluate the expression.
TL;DR
Your problem is that unqualified expression will be evaluated before being passed, and this is done to avoid confusion or ambiguity (per examples).
Here is my method for allowing quick date entry into a User Defined Function without wrapping the date in quotes:
Function cont(requestdate As Double) As Date
cont = CDate((Mid(Application.Caller.Formula, 7, 10)))
End Function
The UDF call lines up with the OP's initial request:
=cont(12/12/2012)
I believe that this method would adapt just fine for the OP's more complex ask, but suggest moving the date to the beginning of the call:
=cont(12/12/2012,a1,b1,c1)
I fully expect that this method can be optimized for both speed and flexibility. Working on a project now that might require me to further dig into the speed piece, but it suits my needs in the meantime. Will update if anything useful turns up.
Brief Explanation
Application.Caller returns a Range containing the cell that called the UDF. (See Caveat #2)
Mid returns part of a string (the formula from the range that called the UDF in this case) starting at the specified character count (7) of the specified length (10).
CDate may not actually be necessary, but forces the value into date format if possible.
Caveats
This does require use of the full dd/mm/yyyy (1/1/2012 would fail) but pleasantly still works with my preferred yyyy/mm/dd format as well as covering some other delimiters. dd-mm-yyyy or dd+mm+yyyy would work, but dd.mm.yyyy will not because excel does not recognize it as a valid number.
Additional work would be necessary for this to function as part of a multi-cell array formula because Application.Caller returns a range containing all of the associated cells in that case.
There is no error handling, and =cont(123) or =cont(derp) (basically anything not dd/mm/yyy) will naturally fail.
Disclaimers
A quick note to the folks who are questioning the wisdom of a UDF here: I've got a big grid of items and their associated tasks. With no arguments, my UDF calculates due dates based on a number of item and task parameters. When the optional date is included, the UDF returns a delta between the actual date and what was calculated. I use this delta to monitor and calibrate my calculated due dates.
All of this can absolutely be performed without the UDF, but bulk entry would be considerably more challenging to say the least.
Removing the need for quotes sets my data entry up such that loading =cont( into the clipboard allows my left hand to F2/ctrl-v/tab while my right hand furiously enters dates on the numpad without need to frequently (and awkwardly) shift left-hand position for a shift+'.

ireports disregarding my settings

I am currently using an XML datasource and I have the date patterns as well as the number pattern set up as dd/mm/yyyy and #,##0.00 respectively, however the data I am pulling from the fields with Xpath is not following this pattern.
an example of a date I am catching is : 2014-02-12 16:00:15 while a price will appear as 40.0000000000.
I also clicked on the aformentioned fields and went into properties, and under pattern I changed it to currency as the numbers refer to prices and set decimals to 2, the problem remains.
After some trial & error I came to this method that worked wonders.
new Double(Double.parseDouble($F{Precio_unidad-price_unit}))
setting this in the TexytFieldExpression will actually do what is neccesary, the report now prints the correct number of decimals.

Return value of ssas dimension property?

I have two dimension properties "Project Start" and "Project End" that belong to my [Project] dimension. They stand for the start and end date of my projects. Now I want to use these values with MDX, or to be more precisely, in an IIF statement in my query. I want to now if one or both properties are after or before some parameters (projectstart ([Time].[Year - Month - Day].[Month].&[2012-01-01T00:00:00]) and projectend).
So I started to try things like this:
Format([Project].[ParentProject].CURRENTMEMBER.PROPERTIES("Project End"), "yyyy-mm-dd") > StrToMember("[Time].[Year - Month - Day].[Month].&[2012-01-01T00:00:00]")
[Time].[Year - Month - Day].[Month].&[2012-01-01T00:00:00].MEMBER_KEY > [Project].[ParentProject].CurrentMember.Properties("Project End")
CDate([Time].[Year - Month - Day].[Month].&[2012-01-01T00:00:00].MEMBER_KEY) > CDate([Project].[ParentProject].CurrentMember.Properties("Project End"))
But either I get an error or the wrong case of the IIF-statement is executed. After chechkig up MSDN what I get from "[Project].[ParentProject].CurrentMember.Properties("Project End")" I'm more than confused now. On the one hand it says that I will get a string, but on the other hand (if there is a TYPED in the property definition) I should get back the data type of the value (in this case DateTime). I wonder what is right now and/or if I understood the MSDN wrong.
Maybe somebody can help me to clear that up and give me a hint how I can work with these properties.
Okay, after spending some more time on finding the answer I have changed my MDX query quite a lot. This resulted in the fact, that I ended up with a query including the Format function and "yyyy-mm-dd" as aiming format. But the conversion didn't work and said, that it can't convert my property value into a date. The returned value of the property was at least for a human recognisable as a date (I wrote a simple MDX query to have a look at what I get).
So obviously the data type of a dimension property seems really to be a string.