hopefully someone can help with this.
I am building a cube in SQL Server Data Tools 2015 and have imported my tables. I want to create a measure that basically says if a date column is 30 days older than todays date and another column is null and another column is "yes" then 1, else 0. All these columns are on the same table.
I guess I am looking for the DAX equivalent of a case statement.
Can anyone help? I have tried google but can't find anything specific to what I need.
Appreciate any help
This can be done with an IF() function:
Calculated Column = IF(Table1[Date] < TODAY() - 30 && Table1[Col2] = BLANK(), 1, 0)
where Table1 is the table these columns live on and Col2 is the "another column" you mentioned.
Related
I have the following table in SQL:
Start - End - Amount **per day**
06.07.2020 10.07.2020 10
08.07.2020 08.07.2020 5
08.07.2020 15.07.2020 20
02.07.2020 06.07.2020 3
Now I want to filter this table by the calendar week. Let's say "where [calendar week] = cw28". cw28 is from the 06th of july to the 12th of july.
With that I'd like to have the sum of the amount of the days that lie between those two dates. One single number.
I'm using MS SQL Server (SQL Express).
I can't figure out how to distinguish (and break down) if one day lays between the two date values or not. And if yes how much I need to sum up.
I tried to make a picture in excel to create a logic from this:
"Logic" in Excel
Can anyone help me with this? :)
Thx and Best!,
Max
Not sure about your exact requirement. But below is the query to get the sum of values between two dates.
select sum(amount_of_days) from table where date_column between '06-JUL-2020' and '07-JUL-2010';
Change the column name and table name according to your requirement
I am trying to make a query to manually consolidate values. The concept is "every -ve value should kick off +ve entries on the basis of FIFO"
Kindly help me in this regard. I have been doing this though stored procedure with a bunch of CASE expressions but still no success.
It's like running an excel vlookup for =bal*-1 but in SQL format :) ......
SELECT *
FROM <table>
WHERE (BAL <> BAL*-1)
should give you every row where the balance is not equal to *-1 of the other balance
I am new with Datazen and trying some comparison options. Is it possible to compare values with that of one year before? All the data is available, so it seems unnecessary to copy the whole datatable and deduct one year of the date.
It is possible. However the calculation needs to be done in your SQL/MDX.
So you will need to have a "this year" measure/value and a corresponding "last year" measure/value.
Simply having all the data that you need in a dataset will not solve your problem as you can't do any sort of custom calculations in Datazen.
Below an example with MDX. In date field select the date that you want to compare with the parallel 1 year ago.
SELECT
{[Measures].[Internet Order Quantity]} ON 0
, {[Date].[Calendar].[Date].[March 22, 2004]
, ParallelPeriod([Date].[Calendar].[Calendar Year]
, 1
, [Date].[Calendar].[Date].[March 22, 2004]
)
} ON 1
FROM [Adventure Works]
If you want to compare two or more years in the same time chart I've hacked a solution for this earlier. I've made a column in my MDX that pulls out the year so I can use this as the series name column. Then if my data f.ex is monthly I've updated all the months to point to the same year. Meaning I have a column with three values for 1/1/2015, but in my series name column I have 2013, 2014 and 2015 so I can chart something like this.
It is a hack, but I've found it to be useful in some occasions.
Thank you for your answers. I solved it myself by making a new view with
DATEADD (year,1,usedDate)
Comparing these two views gives the right solution too.
I have two parameters: 'from month' and 'to month'. I would like to show data between those months. This is my situation:
with member [Measures].[Ordercount Y-1] as '([Year].PrevMember, [Measures].[Ordercount])'
member [Measures].[Growth] as IIF([Measures].[Ordercount Y-1] >0,
[Measures].[Ordercount]/[Measures].[Ordercount Y-1] *100,0)
select {[Measures].[Growth]} ON COLUMNS,
NON EMPTY {[Year].[" +year+ "]} ON ROWS
from [Ordercube]
Its a dialchart, I want to show the % of sales compared to last year in combination with a range between months.
In SQL it would be easy: Where month >= frommonth and month <= tomonth.
Since you can only slice once in a MDX query I don't know what to do.
I hope someone can help me.
Thanks in advance
Actually, you'd find that SQL wouldn't be quite as easy if the months weren't both in the same year :)
Either way, what you're looking for is something like this:
select NON EMPTY {[Measures].[Quantity]} ON COLUMNS,
NON EMPTY [Markets].Children ON ROWS
from [SteelWheelsSales]
where {([Time].[2003].[QTR1] : [Time].[2004].[QTR2])}
This query was written against pentaho's data warehouse. I haven't the faintest clue what your data wharehouse looks like so I don't know what to use in the time dimension for your query, but it's the ([Time].[2003].[QTR1] : [Time].[2004].[QTR2]) syntax you're looking for, I think.
(disclaimer: I'm one of the CDF core developers, but my MDX sucks)
EDIT: In this particular case (Range Operator Reference) the reference site isn't particularly explicit, but the MSDN reference site for MDX is pretty good, so here's the general MDX Reference Site.
I am new to MDX expressions and queries and I am currently looking for something like this -
I have two dates 'Date1' & 'Date2' in Fact Table as Foreign Keys to DATE dimension. I need to do a count of rows where Date1 < Date 2, keeping in account that I don't want to count NULLS. I wrote an expression something like this -
WITH MEMBER [Measures].[RecordCount] AS
COUNT(FILTER([Measures].[RecordCount], IIF([Date1].[Date] <= [Date2].[Date],0,1)=1))
SELECT [Measures].[RecordCount] ON 0
FROM [MYCUBE]
The above queries runs fine, but the count turns out to be incorrect. I created 7 rows in my fact table where Date1 is less than Date2, but still I receive the count as 0.
Any help is appreciated. (any reference sites would be good too for future)
Thanks,
Vineet
vineet9860#gmail.com
You can't really do this easily in MDX, the [RecordCount] measure will be aggregated up before you do the comparison of the dates, so you will never get a valid value.
You would be better to create a named calculation in your DSV that has something like
CASE WHEN Date1 < Date2 THEN 1 ELSE NULL END
and then create a measure in your cubes that sums up this new column.