PowerPivot DAX Date Lookup - dax

Would appreciate any help with this, I have a PowerPivot table, and I want to add a Dax column to find the sale by customer the previous week, for each customer on date dd/mm/yy find the value for (dd/mm/yy-7days). Example of what it would be in Excel using SUMIFS, not sure if possible in DAX ? Thanks in advance for your help. Gav

The right way to do any time intelligence calculations is to use a date table or as we call it date dimension. However, I imagine you need this for a quick "non model" calculation, so that case you can use the following DAX:
=
VAR DD =Table1[Date] - 7
RETURN
CALCULATE (
FIRSTNONBLANK( Table1[Value] , 1 ),
FILTER (
Table1,
Table1[Date] = DD
)
)
If this is the answer you were looking, please do not forget to mark this question as answered.

Related

DAX Select a date range in the calendar table

I am looking to select the size of the calendar table, filtering everything before or after some date, much like a slicer does.
I am trying to compute the percentage change between prices of equity indexes between two dates: now and a year ago. The problem is that the same date last year sometimes falls on a non-trading day. In that case I want the code to select the earliest value available.
In a similar situation, where I use a slicer, I implemented this by using FIRSTNONBLANK and LASTNONBLANK functions. This way, if the slicer is set to a non-trading date the system still works.
I am very much a DAX/Power BI novice, interested in the methodology in DAX as much as addressing the current problem.
Thanks in advance.

QlikView add Calculated Dimension within a Table

Hi Guys I am trying to create a table in Qlikview that shows me sales starting from current week (Week 11) and works back Week 10 Week 9 etc to week 52 previous year. I can do this by creating individual expressions but this would be extremely time consuming. I have been trying to write an expression but having no joy. Is there a way i can create these columns within the table using calculated dimension where i can write a formula, something like:
= sum({=$(=Week(today()-52))<=$(=Week(today()))"}>} QTY)
That would create each week and show the qty of sales.
I would use a numeric representation in the script:
create a field in your calendar: year(date)+Num(Week(MyDate), '00') as yearweek
then you can create a variable vStartWeek: =(max(Year)-1)&52
then your expression will be = sum({<yearweek={">=$(vStartWeek)"}>} QTY)
no need for <=Week(today()) unless you already sold something in the future ;D

Calculating total number of days based on the relative date range filter in tableau

I have a date column using which I created a "relative date" filter as follows:
Now I want to create a measure as follows:
SUM(value from another column)/total number of day in that date range.
Can someone help me how to create this measure?? Thanks!!
Assuming you Record Date field is at the day level of detail, you could do:
SUM(value from another column)/countd(record_date)

Dax - how to get average value per day where column x value is y?

I'm trying to figure out how to get average value per day where type is for example of type "Test". This would show
the average value for all rows wich has the type as "Test" and the average of that same day. So all days would
probably get different average values. How would this be done in Dax syntax? Below is a combination of sql
and normal text which might help explain what im trying to archieve.
select average Values per day from mytable where type = test
I'm providing an example table that might make it easier to understand, it's a quite simple question but I
fail to find information on how to solve it, any help or input is highly appreciated, thanks!
You can filter the dataset to calculate the test value average.
AverageTestValues =
CALCULATE ( AVERAGE ( myTable[Values] ), FILTER ( myTable, [Type] = "Test" ) )
This expression calculates the test values average in a given context. If you use the measure in a total context you will get the average of all rows type Test.
Let me know if this helps.

ApplySimple Formula for Current year in Microstrategy

I'd like to nkow how to extract the current year using an ApplySimple formula for an Oracle DB being used on microstrategy.
The formula I tried is :
ApplySimple("to_char(SYSTIMESTAMP,'Year')")
Even though this formula is a valid one - when I try using this formula to create an attribute , and display it in a report , I get no results( blank column )
What I'm essentially trying to do is compare this current year attribute to another year attribute and create afilter based on this.
Any help wll be much appreciated!
I wouldn't bother with ApplySimple at all, it can be done directly in a filter.
Qualify on the attribute form that you want to compare (presumably the Year ID), and then in the Operator section, change the dropdown from its default 'Value' to 'Custom'.
This allows you to use MicroStrategy's built-in functions in your qualification. The current year can be returned by putting:
Year(CurrentDate())
for your comparison.
Are you sure you want to compare the string "twenty fourteen"? Because, TO_CHAR(SYSTIMESTAMP,'year') would return that. Instead, you might need the YYYY format :
TO_CHAR(SYSTIMESTAMP,'YYYY')
But that is still a string.
You probably need NUMBER :
So, I would prefer, EXTRACT(YEAR FROM SYSTIMESTAMP) Because, this will return 2014 as NUMBER.
SQL> SELECT EXTRACT(YEAR FROM SYSTIMESTAMP) FROM DUAL;
EXTRACT(YEARFROMSYSTIMESTAMP)
-----------------------------
2014
Formula
If the attribute is NUMBER data type, you might need this formula :
ApplySimple("EXTRACT(YEAR FROM SYSTIMESTAMP)")

Resources