Dax to find previous day sale based on data availability - sql-server

I have created one measure in SSAS tabular called "Yesterday Sales by using max(date)-1", with this I am getting blanks if data is not present for max(date)-1. how to get the sales for the next available date.
for Example, my max(date) is 2019-11-25 and before that I have data for 2019-11-22. I don't have data for 23rd and 24th, in this case, I want to show "yesterday sales" for 2019-11-22. can you help to achieve this through Dax?

have you looked up LASTNONBLANK()?
https://exceleratorbi.com.au/lastnonblank-explained/
http://sqljason.com/2012/06/lastnonempty-in-tabular-mode-part-1.html

Related

How can I apply 2 date controls on report/page level?

I want to know if it is possible to have 2 date range controls on my page. Each date range control would be connected to a different date (Purchase date / Consumption date) of our products).
Here is a simplified editable copy of the data studio report.
The Google Sheet source looks like:
ID
Purchase date
Consumption date
Product
Price
ABCD12
21/03/2022
09/11/2022
A
£50
EFGH34
22/03/2022
22/11/2022
B
£80
IJKL56
23/04/2022
15/11/2022
A
£50
MNOP78
24/03/2022
06/12/2022
A
£50
The output I'm looking for is to be able to filter data so that I can answer the question "how many products were purchased in March 2022 that have a consumption date in November 2022". The expected output is as follows:
ID
Purchase date
Consumption date
Product
Price
ABCD12
21/03/2022
09/11/2022
A
£50
EFGH34
22/03/2022
22/11/2022
B
£80
Supermetrics has a Date Picker that essentially does what I need it to do. But it has 2 downsides 1) it is bulky and does not work well with many years of data and 2) It does not allow breaking down to more than a monthly level.
Is there another way to make this happen with parameters?
Through this post I've gotten as far as getting a 'switch' for my graphs and tables between the two date datapoints, but that is not the solution I'm looking for.
actually you did find already a good solution by the 3rd party Add-one "Date Picker" from Supermetrics. An alternative route is to include two tables which only have the consumption date as a column. The user can then select these and do a cross filtering of the main table.
In the first table, the dimension has to be changed to "Year Month":
An alternative community visualisation to the Date Picker (based on the limitations cited in the question) would be the Range Slider.
Two Range Sliders could be used (one for each date field), however, the below will use one Date range control and one Range Slider to demonstrate that they can work together (as well as maintaining the original setup in the question):
1) Purchase date
1.1) Date range control
1.2) Table
Date Range Dimension: Purchase date
Dimension 1: ID
Dimension 2: Purchase date
Dimension 3: Consumption date
Dimension 4: Product
Metric: Price
2) Consumption date
2.1) Range Slider
Column to filter on: Consumption date
(Chart Interactions) Cross Filtering: ☑
Publicly editable Google Data Studio report (embedded Google Sheets data source) and a GIF to elaborate:

How to sum up the records on an Object with respect to a Month

Hello there Salesforce experts,
I have an Object Monthly_cc__c where there are records flowing in for each country every month.
Below are the fields
ID is the record ID
Processing Date
Processing Year
Processing Month
Distributor__c is the Master-Detal relation ship with Account.
Operating Company (IND, AUS, GBR...)
Now for every record there are the below fields
Personal CC
Monthly CC
For each Operating company these results are being sent and for the same Processing date we have various records for different Operating companies.
I would like to sum up the Personal cc for January for us to not complicate our SQL query.
Please let us know a solution on how to accomplish this task.
Thank you.
The expected result would be
For January, 2017
Personal CC = sum(AUS,IND,GBR'S Personal CC)
Monthly CC = Sum(AUS,IND,GBR'S Monthly CC)
You have lots of options here and final result also depends on whether your company uses currency management (is CurrencyIsoCode field present on all objects?).
This should be what you're asking for:
SELECT Distributor__c, SUM(Personal_CC__c) personal, SUM(Monthly_CC__c) monthly
FROM Monthly_CC__c
WHERE Processing_Year__c = 2017 AND Processing_Month__c = 1
GROUP BY Distributor__c
LIMIT 200
This should be bit more flexible:
SELECT Distributor__c, Processing_Year__c, Processing_Month__c, SUM(Personal_CC__c) personal, SUM(Monthly_CC__c) monthly
FROM Monthly_CC__c
GROUP BY Distributor__c, Processing_Year__c, Processing_Month__c
LIMIT 200
Read up about SOQL, GROUP BY & aggregate functions, GROUP BY ROLLUP().
Your data looks to be bit artificially split into day-month-year. If you have real date fields there are ways to GROUP BY CALENDAR_MONTH().
And last but not least - if this query results will be processed in Apex - you need to read about AggregateResult.
P.S. You should work on your questions. We're not writing code for you. What have you tried, what part you're stuck on? If you're completely new to salesforce and don't even know what to experiment with - start with SQOL-related Trailheads

Google Data Studio date aggregation - average number of daily users over time

This should be simple so I think I am missing it. I have a simple line chart that shows Users per day over 28 days (X axis is date, Y axis is number of users). I am using hard-coded 28 days here just to get it to work.
I want to add a scorecard for average daily users over the 28 day time frame. I tried to use a calculated field AVG(Users) but this shows an error for re-aggregating an aggregated value. Then I tried Users/28, but the result oddly is the value of Users for today. The division seems to be completely ignored.
What is the best way to show average number of daily users over a time frame? Average daily users over 10 days, 20 day, etc.
Try to create a new metric that counts the dates eg
Count of Date = COUNT(Date) or
Count of Date = COUNT_DISTINCT(Date) in case you have duplicated dates
Then create another metric for average users
Users AVG = (Users / Count of Date)
The average depends on the timeframe you have selected. If you are selecting the last 28 days the average is for those 28 days (dates), if you filter 20 days the average is for those 20 days etc.
Hope that helps.
I have been able to do this in an extremely crude and ugly manner using Google Sheets as a means to do the calculation and serve as a data source for Data studio.
This may be useful for other people trying to do the same thing. This assumes you know how to work with GA data in Sheets and are starting with a Report Configuration. There must be a better way.
Example for Average Number of Daily Users over the last 7 days:
Edit the Report Configuration fields:
Report Name: create one report per day, in this case 7 reports. Name them (for example) Users-1 through Users-7. These are your Row 2 values. You'll have 7 columns, with the first report name in column B.
Start Date and End Date: use TODAY()-X where X is the number of days previous to define the start and end dates for each report. Each report will contain the user count for one day. Report Users-1 will use TODAY()-1 for start and end, etc.
Metrics: enter the metrics e.g. ga:users and ga:new users
Create the reports
Use 'Run reports' to have the result sheets created and populated.
Create a sheet for an interim data set you will use as the basis for the average calculation. The first column is date, the remaining columns are for the metrics, in this case Users and New Users.
Populate the interim data set with the dates and values. You will reference the Report Configuration to get the dates, and you will pull the metrics from each of the individual reports. At this stage you have a sheet with date in first columns and values in subsequent columns with a row for each day's values. Be sure to use a header.
Finally, create a sheet that averages the values in the interim data set. This sheet will have a column for each metric, with one value per column. The one value is calculated from the series in the interim data set, for example =AVG(interim_sheet_reference:range) or any other calculation you'd like to do.
At last, you can use Data Studio to connect to this data source and use the values. For counts of users such as this example, you would use Sum as the aggregation field type when you are creating the data source.
It's super ugly but it works.

Group by array or shared value

My invoice report pull due dates depending on the selection of Payment Plan Code on UI (either semi, monthly, quarterly, annually, or even 18 installments.) It also accordingly pulls gross premium per due date. I need to pull this table per due date and the sum of the gross premium if they fall into one due date.
What I do is break and save the due dates into array. How can I group by them? Crystal doesn't seem to allow me to group by a shared value, or group by array.
You don't need array for this purpose.. using array complicates the report instead you can manipulate grouping like below:
Create a formula like below and use this formula to group.
if parameterselection = "monthly"
then Month(duedate)
else if parameterselection = "yearly"
then Year(duedate)
.
.
.
.
formula till end
Edit-------------------------------------------
In this case as per your comment you need to create one more group (Group2) with due date.
Now you have two groups group 1 is the one I wrote first and group2 using due date and this works

Crystal Report for Average Tickets revived by hour per month

I need to pull a report that show the avg tickets we receive per hour for a month.
So far I've been able to come up with:
SELECT "TASKS"."WO_NUM", "TASKS"."TASK", "TASKS"."COMPLETED", "TASKS"."OPENDATE",
"TASKS"."REQUEST", "TASKS"."RESPONS"
FROM "TRACKIT9_DATA"."dbo"."TASKS" "TASKS"
WHERE ("TASKS"."OPENDATE">={ts '2015-09-01 00:00:00'} AND
"TASKS"."OPENDATE"<{ts '2015-09-04 00:00:00'})
However this only show the number of ticket we received each hour per day and the report is a mess if I ask for a full months worth of data.
How would I go about asking Crystal Reports to Pull the data then Group it by Hour then give me an average?
You can do this in crystal report.
Group by month then create a formula and write as
Hour(database date field)
Use this to group as a second group after month, now try to manipulate the data

Resources