Why does this DAX relationship between tables not aggregate as expected? - dax

A very basic question about relationships between tables:
I have made a test with two tables ("Dates" and "Facts") and have connected them via an ID field:
When I try to count and group the count by Dates[YearMonth], I am only getting the expected results for the Facts[BirthID] column, and not for the Facts[StartID] or Facts[EndID]. So I am only getting the expected results from the column that is the relationship to the Dates table (where the YearMonth column is that I am trying to group by. This screenshot shows the tables, expected results and actual results:
This is probably very simple, but I can't figure out why it is not aggregating the data "correctly" by YearMonth.
Could someone explain to me what I am doing wrong?

We get same count for Facts[StartID] or Facts[EndID] because the join is on BirthID. If we change the join to use Facts[StartID] or Facts[EndID] we get the expected results as you have shown.
We can also create inactive relationship and activate the relationship with DAX USERELATIONSHIP function. Then we get the expected results.
USERELATIONSHIP

Related

How can I filter by a value inside a pivot table using 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!

Laravel (using Livewire ) to show result from 2 different tables

I am running Laravel 5.8 and hammering my head all day against walls, to find out how to achieve this MySQL query in Laravel -> render function in my livewire component to list all available "ABKs" which include a specific text in the other table "Parts".
What I have:
2 Tables one is ABKs and the other one is PARTs < relation between them is on to many one ABK can have one part, one Part can have many ABKs. Noted the relationship in the Models, works as expected.
But if I try right now to search over both tables(to order and paginate in my livewire component) I need to have this query for example in Laravel:
SELECT * FROM `abks` LEFT JOIN parts ON abks.part_id = parts.id WHERE parts.zeichnungsnummer LIKE '%46%'
if I try this in Tinker I get the result:
$abks = ABK::where('id', 'like','%%')->with('part')->where('parts.zeichnungsnummer','like','%46%')->get();
Illuminate/Database/QueryException with message 'SQLSTATE[42S22]:
Column not found: 1054 Unknown column 'parts.zeichnungsnummer' in
'where clause' (SQL: select * from abks where id like %% and
parts.zeichnungsnummer like %46%)',
what am I doing wrong here? Why doesn't Eloquent find this column?
just a short example what I want to achieve because my code is more complex to post here ... I think its easier to understand to post it in a little example.
a little further explanation why I need this: I have a data table which outputs all ABKs and have 2 search inputs one for the ABKs columns and one for the PARTs columns -> where the user can search for texts in ABKs and in the other one in the PARTs table. which is filtered in this way in livewire while the user types...
Thanks to all here for your great answers, and helping us a lot to learn and understand.
you missed join clause from your eloquent query:
$abks = ABK::where('id', 'like',$abksId)
->join('parts','parts.id','=','abks.part_id')
->where('parts.zeichnungsnummer','like','%46%')->get();

How to get the matching data from two tables?

I'm used to compare 2 data, one data has an id and the other data is the one that needs comparing to get the matching datas. see code below.
DB::table('requests')->where('reqItem',$inventory->invItem)->get();
The code shown above displays all requests information that equals to the compared inventory item.
Now what i want to do now is to compare 2 tables without any id (ex. $inventory->invItem). I don't know how to ask this question but i hope you get what i mean. The figure below shows the way i wanted it to be.
You can run this query. Here, 'inventory' is the name of second table (change it accordingly)
DB::table('requests')
->join('inventory', 'requests.reqItem', '=', 'inventory.invItem')
->select('inventory.reqItem')
->get();

SSRS Tablix Cell Calculation based on RowGroup Value

I have looked through several of the posts on SSRS tablix expressions and I can't find the answer to my particular issue.
I have a dashboard I am creating that contains summary data for various managers. They are entering monthly summary data into a single table structured like this:
Create TABLE OperationMetrics
AS
Date date
Plant char(10)
Sales float
ReturnedProduct float
The data could use some grouping so I created a table for referencing which report group these metrics go into looks like this:
Create Table OperationsReport
as
ReportType varchar(50)
MetricType varchar(50)
In this table, 'Sales' and 'ReturnedProduct' are the Metric column, while 'ExecSummary' or 'Quality' are ReportType entries. To do the join, I decided to UNPIVOT the OperationMetrics table...
Select Date, Plant, Metric, MetricType
From (Select Date, Plant, Sales, ReturnedProduct From OperationMetrics)
UNPVIOT (Metric for MetricType in (Sales, ReturnedProduct) UnPvt
and join it to the OperationsReport table so I have grouped metrics.
Select Date, Plant, Metric, Rpt.MetricReport, MetricType
FROM OpMetrics_Unpivoted OpEx
INNER JOIN OperationsReport Rpt on OpEx.MetricType = Rpt.MetricType
(I understand that elements of this is not ideal but sometimes we are not in control of our destiny.)
This does not include the whole of the tables but you get the gist. So, they have a form they fill in the OperationMetrics table. I chose SSRS to display the output.
I created a tablix with the following configuration (I can't post images due to my rep...)
Date is the only column group, grouped on 'MMM-yy'
Parent Row Group is the ReportType
Child Row Group is the MetricType
Now, my problem is that some of the metrics are calculations of other metrics. For instance, 'Returned Product (% of Sales)' is not entered by the manager because it is assumed we can simply calculate that. It would be ReturnedProduct divided by Sales.
I attempted to calculate this by using a lookup function, as below:
Switch(Fields!FriendlyName.Value="Sales",SUM(Fields!Metric.Value),
Fields!FriendlyName.Value="ReturnedProduct",SUM(Fields!Metric.Value),
Fields!FriendlyName.Value="ReturnedProductPercent",Lookup("ReturnedProduct",
Fields!FriendlyName.Value,Fields!Metric.Value,"MetricDataSet")/
Lookup("Sales",Fields!FriendlyName.Value,Fields!Metric.Value,
"MetricDataSet"))
This works great! For the first month... but since Lookup looks for the first match, it just posts the same value for the rest of the months after.
I attempted to use this but it got me back to where I was at the beginning since the dataset does not have the value.
Any help with this would be well received. I would like to keep the rowgroup hierarchy.
It sounds like the LookUp is working for you but you just need to include the date to find the right month. LookUp will return the first match which is why it's only working on the first month.
What you can try is concatenating the Metric Name and Date fields in the LookUp.
Lookup("Sales" & CSTR(Fields!DATE.Value), Fields!FriendlyName.Value & CSTR(Fields!DATE.Value), Fields!Metric.Value, "MetricDataSet")
Let me know if I misunderstood the issue.

Can BIRT use the output of one query as the input for another query

I have a report that needs to be generated from two different queries.
The first query retrieves a list of information from one data source
The second query must then be called once for each of the records returned by the first query?
Each result set from the second query will then be displayed in separate report tables.
Any pointers are welcome.
It is not possible to perform a SQL join on the first and second query.
Yes this is possible lets assume you have bind your first query results to data table. you can create another table inside the parent table cell and assign your 2 data set to that table with filter of dataset 1
http://publib.boulder.ibm.com/infocenter/rmc/v7r5m0/index.jsp?topic=/org.eclipse.birt.doc/birt/birt-13-1.html
http://publib.boulder.ibm.com/infocenter/rmc/v7r5m0/index.jsp?topic=/org.eclipse.birt.doc/birt/birt-13-2.html
The functionality I require is provided by SubReports
http://www.eclipse.org/birt/phoenix/examples/reports/birt2.1/subreport/index.php

Resources