I have two tables: 1. Sender 2. Dates
In sender tables, i have data about the sender like sender name, product type, sending date, arriving date, cost, and much more. In the sender table, data is for two years: 2020 and 2021.
In 2021, New Sender has come. This new sender is not sending any packages in 2020. So I want to create a new table that only consists of data about the new sender.
How can do it with DAX?
Thank you.
You can do this by CreatingNewTable from DAX; Something like:
NewSenders =
var allSenders = VALUES('sender'[YourSenderID])
var SenderFromHistory = CALCULATETABLE(VALUES('sender'[YourSenderID]), 'sender'[Date] < DATEVALUE("2021-01-01"))
var OnlyNew = EXCEPT ( allSenders , SenderFromHistory )
return
CALCULATETABLE('sender', 'sender'[YourSenderID] in OnlyNew)
Related
I am very new to the PowerBI community and I am confused about how to visualize and create measures/columns for the data which requires comparing last week/month/year data with respect to the current week.
I have tried various solutions available on the internet or other forums. I would appreciate it if anyone can please outline the steps required to achieve the goal.
The data that I have is transactional data and I have also created a Date Table. I am not sure how to go ahead with the problem.
You can create measures like this (for days):
PreviousDay =
var __DayOnRow = SELECTEDVALUE(Calendar[day])
return
CALCULATE( SUM(Table[SomethingToSum]), FILTER(ALL(Calendar),Calendar[day] = __DayOnRow -1 ))
How this work:
SELECTEDVALUE gets a specific day from the current context
__DayOnRow -1 give us a previous Day (not yesterday date< except for today date>)
FILTER with ALL, remove every filter on Calendar (current row is also a filter, so without removing filter we get two excluding conditions )
How do that for WEEK?
PreviousWeek =
var __WeekOnRow = SELECTEDVALUE(Calendar[Week])
var __FirstDayOfWeek = calculate(min(Calendar[Day]), FILTER(ALL(Calendar), __WeekOnRow = Calendar[Week] ))
var __LastDayOfWeek = calculate(max(Calendar[Day]), FILTER(ALL(Calendar), __WeekOnRow = Calendar[Week] ))
return
CALCULATE(SUM(Table[SomethingToSum]), FILTER(ALL(Calendar),Calendar[day] >= __FirstDayOfWeek -7 && Calendar[day] <= __LastDayOfWeek -7 ))
Recently we observed that when a user tries to complete a transaction on our website using an ios device. Apple ends the current session and begins a new session. The difficulty with this is that if the user came through paid source/email the current session ends and starts a new session with apple.com traffic source.
For Instance
google->appleid.apple.com
(direct)->appleid.apple.com
email->appleid.apple.com
ios->appleid.apple.com->appleid.apple.com->appleid.apple.com
Since we have this raw data coming into BQ we are looking at replacing appleid.apple.com with their actual traffic Source i.e. google,direct,email,ios.
Any help regarding the logic/function to workaround this problem will help?
This is the code I tried implementing:
WITH DATA AS (
SELECT
PARSE_DATE("%Y%m%d",date) AS Date,
clientId as ClientId,
fullVisitorId AS fullvisitorid,
visitNumber AS visitnumber,
trafficSource.medium as medium,
CONCAT(fullvisitorid,"-",CAST(visitStartTime AS STRING)) AS Session_ID,
trafficsource.source AS Traffic_Source,
MAX((CASE WHEN (hits.eventInfo.eventLabel="complete") THEN 1 ELSE 0 END)) AS ConversionComplete
FROM `project.dataset.ga_sessions_20*`
,UNNEST(hits) AS hits
WHERE totals.visits=1
GROUP BY
1,2,3,4,5,6,7
),
Source_Replace AS (
SELECT
Date AS Date,
IF(Traffic_Source LIKE "%apple.com" ,(CASE WHEN Traffic_Source NOT LIKE "%apple.com%" THEN LAG(Traffic_Source,1) OVER (PARTITION BY ClientId ORDER BY visitnumber ASC)end), Traffic_Source) AS traffic_source_1,
medium AS Medium,
fullvisitorid AS User_ID,
Session_ID AS SessionID,
ConversionComplete AS ConversionComplete
FROM
DATA
)
SELECT
Date AS Date,
traffic_source_1 AS TrafficSource,
Medium AS TrafficMedium,
COUNT(DISTINCT User_ID) AS Users,
COUNT(DISTINCT SessionID) AS Sessions,
SUM(ConversionComplete) AS ConversionComplete
FROM
Source_Replace
GROUP BY
1,2,3
Thanks
Does assuming the visitStartTime as key to identifying the session start help? Maybe something like:
source_replaced as (
select *,
min(Traffic_Source) over (
partition by date, clientid, fullvisitorid, visitnumber order by visitStartTime
) as originating_source
from data
)
Then you can do your aggregation over the originating_source. Its kind of difficult without looking at some sample of data about whats going on.
Hope it helps.
Using the NetSuite web service I am creating a sales order. The result that comes back only contains the internalId for the sales order. The email that goes to the customer shows the tranid however (shown as the "Order Number"). Is there a way to return the tranid when creating the sales order so that I don't have to make a second API call to get the order details?
No.
simplest thing is to:
var id = nlapiSubmitRecord(soRec);
var tranId = nlapiLookupField('salesorder', id, 'tranid');
I have a database containing emails and I want to search for a specific date using the regex operator and return all emails sent on that date. I have tried this so far but it doesn't return anything. I am new to regex and am not sure if I'm querying the date correctly.
db.messages.find({'headers.Date' : $regex : '2001-07-06'}})
This example below successfully returned all the emails send from the specified email address.
db.messages.find({'headers.From' : { $regex : 'reservations#merriotts.com' } });
The emails contain the following information:
headers { content transfer encoding, content type, date, from, message id, mime version, subject, to }
You need not make use of regex here, something simpler like this should work:
db.posts.find({"headers.Date": new Date(2001, 06, 06) })
This should work if the dates you saved in the DB are without time (just day, month, year)
Now if you have dates saved with new Date(), which includes the time components as well, then you need to create a date range which includes all the moments for that day :
db.posts.find( //query for all moments/time of a specific date
{"headers.Date": {"$gte": new Date(2001, 6, 6), "$lt": new Date(2001, 6, 7)}})
Note - The API for Date is Date(YYYY,MM,DD) and counting for 'month' starts from '0' and counting for 'date' starts from '1'.
Is it possible to retrieve a List<Date> instead of a List<SomeBean> using Ebean ?
For example, I have this model:
Days(id, name, day);
I'd like to do something like:
List<Date> dates = Ebean.createQuery(Date.class, "SELECT day FROM days").findList();
Of course, this doesn't work and returns this:
PersistenceException: java.util.Date is NOT an Entity Bean registered with this server?
How can I do that?
you can use sqlQuery see SqlQuery in Ebean :
The database retrieves time and date data with a type LocalDateTime
String sql = "select day from days";
List<SqlRow> row = DB.sqlQuery(sql).findList();
List<LocalDateTime> days = row.stream().map(r->(LocalDateTime) r.get("day")).collect(Collectors.toList());