Migrating Measures and calculated columns from Tableau to PowerBi - reporting-services

Stuck at a specific measure calculation which looks like this in tableau
1.) zn(COUNTD(if not isnull([Order_number]) then [Order_number] END)).
I tried using isblank dax function but it is not working as i expected it to be.
How will the same measure be written in Powerbi using DAX?
Problem 2
Simultaneously, not able to get the output for a particular calculated column in powerbi for which the tableau query to derive that particular column looks like this:
2.) zn(IF CONTAINS([Record Type],"High") and datename('weekday',[Activity Date]) = 'Sunday' AND [Location] = '08520' THEN 7 ELSEIF CONTAINS([Record Type],"Junior") and datename('weekday',[Activity Date]) = 'Sunday' AND [Location] = '8520' THEN 7 end
I re created the above by Creating a custom column named it as Day Name deriving day name from the date column and Wrote an equivalent query in Powerbi query editor to create a custom column, query mentioned below. Even though there is no syntax error, it is giving 0 for all the rows in that particular calculated column.
slots= if([RECORD_TYPE]="high" and [Day Name]="Sunday" and [LOCATION]=08520) then 7 else
if([RECORD_TYPE]="Outbound" and [Day Name]="Sunday" and [LOCATION]=3109) then 7 else 0
Any kind of lead or help will be much appreciated.
Thanks in advance

For 1st problem:
zn(COUNTD(if not isnull([Order_number]) then [Order_number] END))
So, If i break this query basically, zn is a function used in tableau to convert all the null values to zero and as countd implies to the entire if statement above.
I was able to write an equivalent dax query for it mentioned below, if anyone out there can tell me or verify if it is correct or not, I'll be really thankful.
IF(ISBLANK(DISTINCTCOUNT(Order_table[ORDER_NUMBER])),0,DISTINCTCOUNT(Order_table[ORDER_NUMBER]))
As far as the second problem goes, im not able to find a solution to it and the value for that column for all the rows stands at 0 as I'm writing this answer to 1st problem. Any kind of help or lead will be much appreciated.
Thanks

Related

Fixed values not accepted in SSRS

I created the above query for a time range, and I am attempting to add it to the parameters
Although this is a fixed value, I am unable to get the query to accept the fixed value.
Is there any other way to approach this?
I think you are approaching this incorrectly. As far as I know you cannot use the results of a query to populate a parameter value like that.
If the below does not work, then I would edit your question, show a sample of the data you are working with, the parameter labels you want to show and then the expected outcome.
At the moment your parameter value will just be a text string that looks like a t-sql query
You probably just need to edit your dataset query and parameter values.
For example. Set you parameters values to
Label
Value
Shift 1
1
Shift 2
2
Shift 3
3
Then your dataset query would look something like
SELECT * FROM myTable
WHERE CAST(myDateTimeColumn AS Time) BETWEEN
CASE #Shift
WHEN 1 THEN CAST('21:00:00' AS Time)
WHEN 2 THEN CAST('22:00:00' AS Time)
WHEN 3 THEN CAST('23:00:00' AS Time)
END
AND
CASE #Shift
WHEN 1 THEN CAST('21:59:59' AS Time)
WHEN 2 THEN CAST('22:59:59' AS Time)
WHEN 3 THEN CAST('23:59:59' AS Time)
END
This won't be perfect as it would miss anything less than a second before a new hour but should get you on the right track.
note: This is also untested as it's done from memory

Using DATEFROMPARTS with RIGHT/CHARINDEX function

Alright so I'm re-writing some scripts that were provided to me and part of the script is constructing a date from two different columns, one of which could contain data such as this 3|15 and then that constructed date is being compared to today's date.
Original query section:
CASE WHEN rs.RecurrencePattern = 'Monthly' AND DAYDIFF((CreateDate(GetYear(rs.ws_wg_mig_start_date),GetMonth(rs.ws_wg_mig_start_date), toint(StrParts(rs.RecurrencePatternParms, '|',1)))),(now())) < 0 THEN GetMonth(rs.ws_wg_mig_start_date)+1
I think this is MySQL but I'm not real sure. I'm trying to recreate this in SQL Server and so far I'm using DATEFROMPARTS and stringing everything together. I'm using a NULLIF(CHARINDEX to get the value after the | but if it doesn't exist, then the whole date field is null. I need another pair of eyes on this before I go insane.
Current SQL Code:
DATEFROMPARTS(datepart(year,rs.ws_wg_mig_start_date),datepart(month,rs.ws_wg_mig_start_date),Convert(int,Right(recurrence_pattern_params, NULLIF(CHARINDEX('|', reverse(recurrence_pattern_params)),0)-1)))

SSRS standalone formulas

I have been working on this for days without being able to solve yet. It's probably simple if you know what you're doing. I'm simply trying to make a standalone formula that is not in a tablix or anything, it's just in a textbox.
Here is an example of my Dataset called Dataset1:
What I am trying to get is a sum of the Actual Cost when the Category is Labor from Dataset1. My current expression is:
=Sum(iif(Fields!Category.Value="Labor", Fields!ActualCost.Value, 0), "Dataset1")
I refer to Dataset1 as my scope because otherwise, I get an error about using an aggregate expression without a scope.
The report runs but shows #Error in the textbox that has my expression in it. When I replace Fields!ActualCost.Value with a 1, I get the answer, 5, which is the correct number of rows with Labor as the Category. But it won't let me sum the numbers in the ActualCost column where Category is Labor.
Any ideas as to what I'm doing wrong? I feel like it's something to do with aggregating, but I'm not sure. Thanks!
It may have to do with the datatype of fields!ActualCost.Value. If that field is a decimal (regardless of how you have it formatted), try using cdec(0) instead of just 0 in your expression.

Access query using calculation

I'm trying to make a query using a calculation with Date().
I have a field named [Currentordue] and a field named [duedate]. What I'm trying to accomplish is making a query to limit the results by "if [currentordue] equals "due" or if [duedate] minus today's date is less than 30 days."
I've tried a few different ways but always seem to end with either an error or with no results showing (which would be an error as well since I know there are fields that are due).
Any and all help would be appreciated.
Here is a way to use two different date conditions:
SELECT Table1.Currentordue, Table1.duedate, DateDiff("d",[duedate],Date()) AS Expr1
FROM Table1
WHERE (((DateDiff("d",[duedate],Date()))<30)) OR (((Table1.Currentordue)=[duedate]));

Concatenating/Merging 2 DataSets with exact same columns [duplicate]

This question already has an answer here:
Merge two Reporting Services datasets into one
(1 answer)
Closed 6 years ago.
I'm trying to figure out if there is any way in Report Builder 3.0 to concatenate or merge 2 different "DataSet" objects which both have exactly the same column names into one set of data, for the purposes of displaying in a pie chart.
My SQL query looks similar to this for both data sets:
DECLARE #DateCreatedStart date = GETDATE()-14
DECLARE #DateCreatedEnd date = GETDATE()
SELECT i.Source, COUNT(*) AS Count_of_Source
FROM [DBName].[dbo].[Items] i
WHERE (i.DateCreated BETWEEN #DateCreatedStart AND #DateCreatedEnd)
GROUP BY i.Source
So I end up with 2 data sets which both have Source and Count_of_Source columns.
Edit: I've found out that I can't use the Lookup function how I thought I might be able to. It just looks in one dataset and finds a match in another dataset, and pulls a value from the same row in a similar manner to Excel's vlookup/hlookup.
Edit more info: I found this answer https://stackoverflow.com/a/24312870/1804496 that showed me I could use a scope parameter on my expression to specify the name of my second data set. I added a second values member that uses an expression =SUM(Fields!Count_of_Source.Value, "DataSet2"), but the chart looks completely wrong and I don't know how to fix it at the moment. It looks like the single row from my second data set is being repeated n times, where n is equal to the number of unique Source values from my first data set. No idea what is going on there.
The best way to combine the datasets is using the SQL Server. So you can just add a new dataset and paste in the two queries with a UNION ALL between them.