How can I filter by a value inside a pivot table using Supabase? - supabase

I'm building a bike rental app where users can reserve bikes for a certain number of days. Bikes and users have a many-to-many relationship, there's a bike_user pivot table that contains the information about reservation start and end dates. See the diagram:
I need to take a range of dates, and filter the bikes, showing only the ones that haven't been reserved between these two dates.
Can you please help me figure out how to do this?

The documentation is not exactly clear on this one, but you can use the inner keyword to filter your results by values from your joined table like this:
const {data, error} = await supabase.from('bikes')
.select('*, bike_user!inner(reservation_start_date, reservation_end_date)')
.gt('bike_user.reservation_start_date', '2022-01-01 15:00:00.000')
.lt('bike_user.reservation_end_date', '2022-11-01 19:00:00.000')
Let me know if this works for you!

Related

Display related data when filtered in Power BI

Hello, here is my dataset :
What I would like to have is a filter on Campagne which shows all the other Campagne if the Contract number is the same. I explain myself. If I click on Campagne 3 in my filter, I want to see 1, 2, 3 and the attribution (the attribution by Campagne, not a Sum). Here is the expected result :
For now, the only solution that I have is to use a "temporary" table. But it's not optimal because I have to duplicate the data.
Any idea ?
Thanks a lot.
You are going to have to create an extra table or two to get the slicer to work how you want. There's no way around it, but you only need to duplicate part of the data. Here's what I would suggest.
Create a new Slicer table by summarizing the Campagne and Contrat columns from your original table.
Slicer = SUMMARIZE(Table1, Table1[Campagne], Table1[Contrat])
Now since you want the filtering to be done by Contrat and this would require a many-to-many relationship with the original table, you need to create a bridge table.
Contracts = VALUES(Table1[Contrat])
Now set up the relationships on Contrat making sure that the Slicer to Contracts relationship has cross-filtering enabled both ways.
Now you can use the Slicer[Campagne] column for your slicer and put Table1[Campagne] on your table and it should filter how you want.

DAX COUNT/COUNTA functions

I've looked at many threads regarding COUNT and COUNTA, but I can't seem to figure out how to use it correctly.
I am new to DAX and am learning my way around. I have attempted to look this up and have gotten a little ways to where I need to be but not exactly. I think I am confused about how to apply a filter.
Here's the situation:
Four separate queries used to generate the data in the report; but only need to use two for the DAX function (Products and Display).
I have three columns I need to filter by, as follows:
Customer (Display or Products query; can do either)
Brand (Products query)
Location (Display query)
I want to count the columns based on if the data is unique.
Here's an example:
Customer: Big Box Buy;
Item: Lego Big Blocks;
Brand: Lego;
Location: Toys;
BREAK
Customer: Big Box Buy;
Item: Lego Star Wars;
Brand: Lego;
Location: Toys;
BREAK
Customer: Big Box Buy;
Item: Surface Pro;
Brand: Microsoft;
Location: Electronics;
BREAK
Customer: Little Shop on the Corner;
Item: Red Bicycle;
Brand: Trek;
Location: Racks;
In this example, no matter the fact that the items are different, we want to look at just the customer, the brand, and the location. We see in the first two records, the customer is "Big Box Buy" and the brand is "Lego" and the location is "Toys". This appears twice, but I want to count it distinct as "1". The next "Big Box Buy" store has the brand "Microsoft" and the location is "Electronics". It appears once and only once, and thus the distinct count is "1" anyway. This means that there are two separate entries for "Big Box Buy", both with a count of 1. And lastly there is "Little Shop on the Corner" which appears just once and is counted just once.
The "skeleton" of the code I have is basically just to see if I can get a count to work at all, which I can. It's the FILTER that I think is the problem (not used in the below example) judging by other threads I've read.
TotalDisplays = CALCULATE(COUNTA(products[Brand]))
Obviously I can't just count the amount of times a brand appears as that would give me duplicates. I need it unique based on if the following conditions are met:
Customer must be the same
Brand must be the same
Location must be the same
If so, we distinctly count it as one.
I know I ranted a bit and may seem to have gone in circles, but I was trying to figure out how to explain it. Please let me know if I need to edit this post or post clarification.
Many thanks in advance as I go through my journey with DAX!
I believe I have the answer. I used a NATURALINNERJOIN in DAX to create a new, merged table since I needed to reference all values in the same query (couldn't figure out how to do it otherwise). I also created an "unique identity" calculated column that combined data from multiple rows, but was hidden behind the scenes (not actually displayed on the report) so I could then take a measure of the unique values that way.
TotalDisplays = COUNTROWS(DISTINCT('GD-DP-Merge'[DisplayCountCalcCol]))
My calculated column is as follows:
DisplayCountCalcCol = 'GD-DP-Merge'[CustID] & 'GD-DP-Merge'[Brand] & 'GD-DP-Merge'[Location] & 'GD-DP-Merge'[Order#]
So the measure TotalDisplays now reports back the distinct count of rows based on the unique value of the customer ID, the brand, and the location of the item. I also threw in an order number just in case.
Thanks!
I am semi new to DAX and was struggling with Count and CountA formula, you post has helped me with answers. I would like to add the solution which i got for my query: Wanted count for Right Time start Achieved hence if anyone is looking for this kind of answer use below, filter will be selecting the table and adding string which you want to
RTSA:=calculate(COUNTA([RTS]),VEO_Daily_Services[RTS]="RTSA")

Parse relational type query - swift 3

I've got 2 classes
Reports - objectID, Title, Date & relationItem ( Relation type column linked up to Items)
Items - ObjectID, Title, Date etc
I want to query all the Items that are equal to a objectID in reports. Users create reports then add items to them. These items are found in the Items table.
I've looked at the https://parseplatform.github.io/docs/ios/guide/#relations but don't see anything for swift3.
I've tried a few things with little success. This snipplet below i did find, but not sure how to apply it to my classes.
var relation = currentUser.relationForKey("product")
relation.query()?.findObjectsInBackgroundWithBlock({
Would love somebody to direct me into the right direction! Thanks
Tried this code below too!
var query = PFQuery(className:"Items")
query.whereKey("relationItem ", equalTo: PFObject(withoutDataWithClassName:"Reports", objectId:"MZmMHtobwQ"))
Ok so i had to change the table slightly to get this to work to prevent a query within a query.
I've added a relation Type to the Items table instead of the Reports Table
Then i managed to retrieve all the Items based of that report ObjectId like this:
let query = PFQuery(className:"Items")
query.whereKey("reportRelation", equalTo: PFObject(withoutDataWithClassName:"Reports", objectId:"3lWMYwWNEj"))
This then worked. Note that reportRelation is the Relational Type Column.
Thanks
When you’re thinking about one-to-many relationships and whether to implement Pointers or Arrays, there are several factors to consider. First, how many objects are involved in this relationship? If the “many” side of the relationship could contain a very large number (greater than 100 or so) of objects, then you have to use Pointers. If the number of objects is small (fewer than 100 or so), then Arrays may be more convenient, especially if you typically need to get all of the related objects (the “many” in the “one-to-many relationship”) at the same time as the parent object.
http://parseplatform.github.io/docs/ios/guide/#relations
If you are working with one to many relation, use pointer or array. See the guide for examples and more explanation.

Qlik sense - Rank() within a specific dimension when you have multiple ones

I am new to Qlik and trying to solve the following issue.
I have a table with two dimensions, one with the entry's unique ID, and one with a category, as in the example below.
Table example
My goal is to create a new column with a ranking of 'Score' - my measure - per category:
Table with desired output
If I use the expression
Rank(Score)
I get a column of ones, as the command takes the most granular dimension (Unique ID) as the default one. If I use
Rank(TOTAL Score)
It obviously returns a ranking regardless of all the dimensions. By reading the documentation and similar questions asked by other users I reckon that it should be possible to specify which dimension to use for TOTAL, with the following syntax:
Rank(TOTAL <Category> Score)
Yet, the formula returns an error and only null column values. I've tried different syntax, use of brackets but I still cannot grasp what I am doing wrong.
Please note that I cannot create the ranking column when loading the data.
I would immensely appreciate if someone were so kind to help on this!
Try with
=aggr(rank(sum(Score)), Category, UniqueID)

Not getting the correct totals using Cognos Report Studio. Need to get totals that show up in column

newparts_calc
if (([MonthToDateQuery].[G/L Account] = 4200 and [Query1].[G_L_Group] = 'NEW')) THEN ([Credit Amount]-[Debit Amount]) ELSE (0)
Data Item1
total([newparts_calc])
I need Data Item1 to return newparts_calc values only.
So for example in 1st row Data Item1 should be 8,540.8, but is 34,163.2
Whats wrong? how do i fix?
REVISED QUESTION
I apologize for not making sense on the original question.
I have many of the calc's that im trying to gather and put on a crosstab. I want to see sales by month (row) and part category (column)
[Query2] is the one shown in picture above.
It joins [MonthToDateQuery] AND [Query1]
The join is on 'Invoice' and carnality is 1..1 = 1..1
[MonthToDateQuery] is based on the package im working in. General ledger. It supplies the g/l entries for each sales g/l account
[Query1] is a SQL query i brought in to be able to break out categories even further from g/l group.
For example g/l account 4300 is rebuilt. However i needed to break out even further to see Rebuilt-Production and Rebuilt-New. I can do that with the g/l group.
I saw in my g/l account ledger entries that it referenced the invoice number. So thats how i tied in my SQL.
So as you can see from the table below (which is the view tabular data from query) i need a total. I have tried plugging newparts_calc into my crosstab and setting aggregation to total but the numbers still dont seem right. I dont think i have something set as it should be.
All the calc's im doing are based on single or multiple G/L Accounts and single or multiple G/L Groups.
Any Advice?
As you can see the problem seems to be duplicate invoice numbers.
How can i fix?
Couple things come to mind:
-Set the processing order to 2
-Since your calc is always a multiple and you are joining two queries, you may need to check your cardinality. Sometimes it helps to add derived queries to ensure you are working with the correct grain.
I'm obviously missing something, but if you want
I need Data Item1 to return newparts_calc values only.
just use newparts_calc, without total? That would give you proper value for row 1 -)
If you need a running-total for days (sum of values for previous days) — you should use a running_total function.
At a guess, one of your two queries is returning multiple rows for each invoice, which will cause this double counting. Look at the output of the two queries and see if that's happening. If so, then you just need to work out how to collapse that down to one row per invoice.
Per your new question - The underlying data has got to be causing the issue. Its clearly not 1:1 (note that even though this is what your stated cardinality is, Cognos does not enforce 1:1). Invoice number is not unique, GL Group is at a lower level.

Resources