Getting first member with MDX - mdx

I want to get the expiration date of a product, however, there could be several expiration dates for the products
ProductID | ExpDate | Qty
1 FY12 1000
2 FY12 1000
2 FY14 1000
3 FY13 1000
3 FY15 1000
As you can see there are several dates for a Product, however, I just want the first ExpDate.
this is my query so far
SELECT NON EMTPY
([Product].[ProductID].[ProductID].MEMBERS *
[Primary Expiration Date].[Primary Expiration Year].[Primary Expiration Year].MEMBERS) on ROWS,
NON EMTPY ([Measures].[Qty]) on columns
FROM Sales_Market
WHERE(
{[Primary Expiration Date].[Primary Expiration Date Hierarchy].[Primary Expiration Quarter].&[FY12-Q4],
[Primary Expiration Date].[Primary Expiration Date Hierarchy].[Primary Expiration Year].&[FY13],
[Primary Expiration Date].[Primary Expiration Date Hierarchy].[Primary Expiration Year].&[FY14],
[Primary Expiration Date].[Primary Expiration Date Hierarchy].[Primary Expiration Year].&[FY15]})
Any help?
Thanks

You can try this query:
SELECT NON EMTPY
Generate([Product].[ProductID].[ProductID].MEMBERS, Subset(NonEmpty({[Product].CurrentMember} * [Primary Expiration Date].[Primary Expiration Year].[Primary Expiration Year].MEMBERS), 0, 1)) on ROWS,
NON EMTPY ([Measures].[Qty]) on columns
FROM Sales_Market
WHERE(
{[Primary Expiration Date].[Primary Expiration Date Hierarchy].[Primary Expiration Quarter].&[FY12-Q4],
[Primary Expiration Date].[Primary Expiration Date Hierarchy].[Primary Expiration Year].&[FY13],
[Primary Expiration Date].[Primary Expiration Date Hierarchy].[Primary Expiration Year].&[FY14],
[Primary Expiration Date].[Primary Expiration Date Hierarchy].[Primary Expiration Year].&[FY15]})
You can add a measure as second argument of NonEmpty if necessary.

Related

Delete the records which are old according to new updated date(Reload Date)

We have a requirement in snowflake that if from below table a person with some booking ID like mark-4683 blocks/books a house from a certain Start Date : 12-02-2023 to End Date :31-03-2023 on a Reload Date:05-10-2022 and again if he comes again and blocks/books the house from Start Date : 12-02-2023 to End Date :17-02-2023 on Reload Date : 19-11-2022, we should delete the previous record i.e one with Reload Date : 05-10-2022
Reload Dato
BOOKING (ID)
Start Date (ID)
End Date (ID)
BOOKING Status Type
05-10-2022
mark-4683
12-02-2023
31-03-2023
BLOCKED
19-11-2022
mark-4683
12-02-2023
17-02-2023
BLOCKED
27-08-2022
mark-4683
19-02-2023
25-02-2023
BOOKED
05-11-2022
mark-4683
02-04-2023
08-04-2023
BOOKED
05-10-2022
mark-4683
09-04-2023
27-10-2023
BLOCKED
05-11-2022
mark-4683
30-04-2023
06-05-2023
BOOKED
05-11-2022
mark-4683
28-05-2023
03-06-2023
BOOKED
so according to our need the dates which are in bold we need to remove those records, could someone help me with this?

Select subscription date range

How to turn a date into last month's date?
SELECT extract(day from (Select (period_start) from accounts where id = 'id')) AS "Day of month";
The above give me the day of the month
Account Table
id (primary)
startPeriod
User records
timestamp
account_id (foreign key)
The user is registered at 02-12for subscription start
I would like to have a query to select the date range from the current month to last month
This current month is April, so I would like to select the record that is
select records from table where date > '03-12-2022'
get the subscription start period and get the date
set the query limited to last month with the subscription start date
how to produce this date 03-12-2022 which is driven by subscription start period and previous month?
many thanks
This approach should work:
Get the number of months between the subscription date and today e.g. age(timestamp1, timestamp2)
Get the number of months and subtract 1 to get last month e.g. duration = extract(month from age(timestamp1, timestamp2)) - 1
Add the months to the subscription date e.g. (subscription_date + (duration || ' month')::INTERVAL)

MKStoreKit Auto Renewing Subscription Expiry Date Always Returns Current Date

Using MKStoreKit for an auto-renewing subscription. Successful purchase in the sandbox. The issue is the purchase date and expiry date always log as the same, or 1hr behind the current date. With accelerated sandbox times I would expect [[MKStoreKit sharedKit] expiryDateForProduct:#"211112"]; to be around 30mins ahead of [NSDate date] on purchase as its a six month purchase. I get the current date exactly 1hr behind for the transaction.
Log for purchase:
Transaction date is 2021-07-30 4:15:07 pm +0000
Subscription end date is Fri Jul 30 17:15:07 2021
On reloading, the logs print that that subscription expiry date and current date are both exactly the same
Log for reloading:
1. Current time and date: Fri Jul 30 17:02:42 2021
2. Expiry date for subscription 6 months = Fri Jul 30 17:02:42 2021
From the code in MKStoreKit, it would seem the purchase date may be returning NULL and returning the current date
-(NSDate*) expiryDateForProduct:(NSString*) productId {
NSNumber *expiresDateMs = self.purchaseRecord[productId];
if ([expiresDateMs isKindOfClass:NSNull.class]) {
return NSDate.date;
} else {
return [NSDate dateWithTimeIntervalSince1970:[expiresDateMs doubleValue] / 1000.0f];
}
}
[[MKStoreKit sharedKit] valueForKey:#"purchaseRecord"] returns <null> on purchase
It was incorrect app secret in MKStorekitConfigs.plist

Archer GRC: Calculate number days between two date fields

When my values list Respondent Status changes to “Completed” I need to Calculate the number days between Date Initiated (date field) and Respondent Status Date Change (date field).
IF([Respondent Status ] = VALUEOF("Completed"),
DATEDIF([Date Initiated ], [Respondent Status Date Change], DAY),
How do I account for it the value isn't Completed? Something with true or false statements?
You can reference the field itself (and it will retain the current value) or a static value.
IF([Respondent Status] = VALUEOF([Respondent Status],"Completed"),
DATEDIF([Date Initiated], [Respondent Status Date Change], DAY),
[FIELD])
IF([Respondent Status] = VALUEOF([Respondent Status],"Completed"),
DATEDIF([Date Initiated], [Respondent Status Date Change], DAY),
0)

How to get Next month date from today date (i.e) exactly one month expires from today date

I have maintained two datas into my table
1 column 2 column
PaidDate validitydate
in padidate ill give insert todaydate. but in validity date i may either insert validity for 1 week/1 month.
I have used validity=DATEADD(Day,7,#paiddate) to insert validity for 1 week. but how to gtet the validity for 1 month from todays date
Isn't that just:
validity = DATEADD(month, 1, #paiddate)
DATE_ADD supports units.