I want to get the first order date for each customer in a new field in Google Data Studio.
For example, I want this result:
cust_id
order_id
order_dateTime
first_order_dateTime
a1
wer
09/13/2018 2:23:10 PM
09/13/2018 2:23:10 PM
a1
sdf
09/13/2018 2:25:07 PM
09/13/2018 2:23:10 PM
a1
aqf
11/24/2018 9:11:43 AM
09/13/2018 2:23:10 PM
b7
nmk
02/15/2018 7:40:14 AM
02/15/2018 7:40:14 AM
c41
dst
03/08/2019 1:33:14 PM
03/08/2019 1:33:14 PM
c41
mvh
04/23/2020 7:51:21 AM
03/08/2019 1:33:14 PM
I get it in Power BI using this code:
first_order_dateTime = CALCULATE(min('table'[order_dateTime]) , ALLEXCEPT('table', 'table'[cust_id]))
but I don't know How can I get it in google data studio.
Note that I want the first_order_dateTime field in DateTime format.
To get this result you need to do:
Create a data combination, combining the base with itself. In the combination, use the cust_id binding key. In the base to the right, insert the dimension order_dateTime, in the base to the left insert the metric with aggregation of type MIN to order_dateTime, calling this metric first_order_dateTime.
After performing the combination, just insert your data into a table to view the result, inserting the cust_id, order_daterTime and first_order_dateTime columns.
]
Related
I'm working with amazon-quicksight and I'm trying to migrate one funcionality from PowerBi to Quicksight but it has not been possible.
The idea is: I have a dataset with two columns "date" and "sales". The user will have a filter with the column "date". More than one date can be selected. Depending on the dates selected by the user we need to get two KPIs, the first one is the sum of sales for those dates (this is already done), but the second one is my problem, it should be the sum of the sales on the same days selected by the user but in the previous year (it depends on which year was selected for each date).
Example:
DataSet:
DATE
SALES
2020-01-05
1
2020-02-01
1
2020-06-10
4
2020-06-17
1
2021-01-01
1
2021-02-01
3
2021-06-10
3
2021-06-15
5
If the user select the dates: 2021-02-01, 2021-06-10 and 2021-06-15, the result should be:
KPI 1: Sum of sales (for those dates): 11
KPI 2: Sum of sales for those dates in the previous year: 5 -> (Days to use 2020-02-01, 2020-06-10 and 2020-06-15)
Do you have any idea about how can I calculate the KPI 2? Any suggestion?
In powerBI this (KPI 2) was done with the function: SAMEPERIODLASTYEAR
Thanks in advance.
I was able to solve this issue taking into account that the user must filter data from the two years, for example 2020 and 2021.
After that, I created the "calculated field":
calc_sum_sales = sum(sales)
After that:
calc_sum_sales_last_year = ({calc_sum_sales}-periodOverPeriodDifference(sum(sales),date,YEAR,1))
After that, I created an "visual table" and added in "group by" the field "date" and in "value" the field "calc_sum_sales_last_year"
I must give click in the column date to agroup by "year". In that way I get just two rows, one row for each year.
Finally, I change the "visual table" to "KPI" and I got the expected result.
I have a filter visual on my dashboard with dates that controls a table. What I'm looking for is if the user selects any date from the filter visual, I want the table to show data from the selected date AND a static date that I define say Dec 31, 2020. So, no matter what date the user selects, the table will always show data from Dec 31, 2020 and the selected date.
Is this possible?
Try this
Single Select = IF(HASONEFILTER(ValueTable[TransDate]), SUM(ValueTable[Value]),0)+ CALCULATE( SUM(ValueTable[Value]), ValueTable[TransDate]=DATE(2020,12,31))
Multi Select = IF(ISFILTERED(ValueTable[TransDate]), SUM(ValueTable[Value]),0)+ CALCULATE( SUM(ValueTable[Value]), ValueTable[TransDate]=DATE(2020,12,31))
I am dealing with a table that has a bunch of short names, ex.
some_id
long_name
short_name
94
March
mar
19
April
apr
0
June
jun
2
September
Sep
I want to grab only a few supported short names, ex. mar, sep, jun.
How would I go about doing it in laravel?
Currently I have something like this:
$this->result = DB::table('table_above')->get();
But this just grabs every table. I was thinking of adding the where command, but not sure how to check for multiple values.
$this->result = DB::table('table_above')->where('short_name', [somehow say either mar, sep, jun])->get();
At the end I'd like an array that holds a dictionary of rows (i.e $result) with the supported short names (i.e here mar, june, sept).
Try this query
DB :: table ('table_above')->whereIn('short_name', ['mar', 'sep'])->get()
I have a detail table in my model with a row for every hour in a day and the sales amount generated to that point of the date. Its not displayed on my report, rather it acts as the base for another reference table in the model:
Datetime Sales
2019-11-10 06:00:00 100.00
2019-11-10 12:00:00 200.00
2019-11-10 18:00:00 500.00
2019-11-10 23:59:59 999.00
The first (reference) table in the model only displays in my report the last hour value of each day in my base table. they are related via the datetime field using a 1:M with a single cross filter setting:
let
Source = Base,
#"Filtered Rows" = Table.SelectRows(Source, each ([Datetime] = #time(23, 59, 59)))
in
#"Filtered Rows"
Datetime Sales
2019-11-10 23:59:59 999.00
2019-11-11 23:59:59 950.00
2019-11-12 23:59:59 900.00
I would like to place a third table on my report that shows each of the hourly rows from the base table when a user clicks on a row in the daily table with the default setting being today's data which is added hourly.
I went down the path of using Power Query to try and filter the base table but have not been able to make it work. Should this instead be done using DAX? Either way, what would the query look like?
thanks in advance!
Thanks, but I have just resolved this. By changing my relationship to use a date field instead of the datetime field, and changing it to a (*:1) type, i am now getting the filter to do what I want. Now just have to figure out how to default to today's date. Thanks again!
I have an Item model.
There are many records in the database with column created_at filled in.
I want to generate a view with such a hierarchy:
2014
December
31
items here
30
items here
29
items here
...
November
31
...
...
2013
...
What's the most elegant way to do that?
EDIT: Thank you so much for queries. How do I get that worked in Ruby on Rails?
To achieve this, we will order the records by the parts of date. Sample query below
SELECT
ItemDescription,
Year(DateField) AS Year,
Datename(mm, DateField) AS Month,
Day(DateField) AS Day
FROM tblName
ORDER BY
Year(DateField) DESC,
Month(DateField) DESC,
Day(DateField) DESC
This will provide you the data in the order expected. Now you can either create a stored procedure to modify the output to the format you need.
SELECT DATEPART(Year, PaymentDate) Year, DATEPART(Month, PaymentDate) Month, DATEPART(day, PaymentDate) Day,item_name
FROM Payments
GROUP BY DATEPART(Year, PaymentDate), DATEPART(Month, PaymentDate),DATEPART(day, PaymentDate) desc
ORDER BY Year, Month,day