POWERBI: take while table when there is no available relation - powerbi

I have a slight issue with my tables in POWERBI. In short, I have a missing link in one of my relations. As a result, instead of returning NOTHING which is logical and actually what I would like, it returns EVERYTHING.
A bit more details, I have the multiple tables with relations between them. The problem is that I have a few task_group pointing toward shipments that do not exist. In my visualization, I am trying to access data (a count of the number of Packages linked to a shipment) that is linked to a shipment. The logical thing for me would be that "If there is no shipment fitting the number that is given in the shipment table, then you cannot count the number of packages linked to that shipment".
But PowerBI beg to differ. His idea is "If I cannot find a shipment to link to package, i'm going to take every single package regardless of shipment". As a result, a group of task that do not have any package end up showing as having all the packages instead. How can I tell powerbi to return nothing if he doesn't find anything instead of returning everything?
Image of my relationships

I think Power BI behaves slightly unintuitively where there are nulls on one side of a join.
Have you tried filtering to only include where shipment_id is not blank?

If the problem is you having NULLs in one side of the relationship, the best way to tackle this would be to replace the NULLs with something else. Now, you can do it in two ways:
Edit the Shipment number NULLs to something else in the Power query while importing (Some number which is not likely to be an actual shipment, maybe 0)
Create a calculated field in DAX replacing the blanks/NULLs and use that in the relationship instead
But I think you may have NULLs in both the sides of the relationship. That is the only explanation I can think of, why Power BI is behaving this way. Either way, the above solutions should fix it.

Related

How to deal with numeric attribute in dimension?

I have a model where in my Project dimension, I have an attribute (AgreedReturn), which is a fixed number.
I included it in my model, all good.
My problem now, is that I have a requirement where users want a SUM of that attribute.
This is very confusing to me... For me, it clearly belongs to the dimension, but, it messes it up that they want ‘math’ applied on it.
What is the right modeling approach to this? Am I forced to move this attribute to the fact somehow?
Numbers in dimensions are not problematic. Including them in calculations is not problematic. For example a Product may have a weight, which you could multiply by a quantity from a fact table to produce a shipment weight.
So your problem is just one of understanding what the users are trying to measure, and figuring out how to calculate it.
And it may well be that it's more convenient to push this attribute to the fact table during ETL, or with a calculated column. But that's a secondary issue.

Build relationship between two tables with Times that are bnot exact but close

I have two tables that i need to build a relationship. They both have a timestamp that I want to use to match the data. The problem is that the timestamps are not exact and my be off by a few seconds,. Eg 8.32.50 and 8.32.45. I could use the hh.mm (change date time to integer)to match the data as but the problem arise in a situation where e.g the times are 8.32.58 and 8.33.067
You will need to set up a time-dimension table. A time-dimension table goes down to the granularity of seconds, so you can relate both tables to that one dimension table so that they can "speak" to one another. Radacad has a great script for creating one here, which also has time-binning columns.

DAX function to get specific value from dimension?

I have a model with DimCustomer, DimSegment and FactRevenue.
For most cases each customer is associated with a single segment.
There are a handful of Customers, that have two Segments… Therefore, in FactRevenue a few few cases of Customers have two Segments associated…
I want to “override” it and display 'current segment' only using FactRevenue (I don’t have a connection between DimCustomer and DimSegment)
Do I have any tools in DAX to achieve this?
Is it viable to have a mapped list of this exceptions and hardcode it somehow?

Google Sheets Array formula for counting the number of values in each column

I'm trying to create an array formula to auto-populate the total count of values for each column as columns are added.
I've tried doing this using a combination of count and indirect, as well as tried my hand at query, but I can't seem to get it to show unique value counts for each column.
This is my first time attempting to use query, and at first it seemed possible from reading through the documentation on the query language, but I haven't been able to figure it out.
Here's the shared document: https://docs.google.com/spreadsheets/d/15VwsL7uTsORLqBDrnT3VdwAWlXLh-JgoJVbz7wkoMAo/edit?usp=sharing
I know I can do this by writing a custom function in apps script, but I'd like to use the built-in functions if I can for performance reasons (there is going to be a lot of data), and I want quick refresh rates.
try:
=ARRAYFORMULA(IF(B5:5="",,TRANSPOSE(MMULT(TRANSPOSE(N(B6:99<>"")), SIGN(ROW(B6:99))))))
In B3 try
=ArrayFormula(IF(LEN(B5:5), COUNTIF(IF(B6:21<>"", COLUMN(B6:21)), COLUMN(B6:21)),))

When to use cte and temp table?

i know this a common question, but most frequently people ask about performancy between this two.
What I'm asking for is use cases of cte and temp table, for better understanding the usage of them
With a temp table you can use CONSTRAINT's and INDEX's. You can also create a CURSOR on a temp table where a CTE terminates after the end of the query(emphasizing a single query).
I will answer through specific use cases with an application I've had experience with in order to aid with my point.
Common use cases in an example enterprise application I've used is as follows:
Temp Tables
Normally, we use temp tables in order to transform data before INSERT or UPDATE in the appropriate tables in time that require more than one query. Gather similar data from multiple tables in order to manipulate and process the data.
There are different types of orders (order_type1, order_type2, order_type3) all of which are on different TABLE's but have similar COLUMN's. We have a STORED PROCEDURE that UNION's all these tables into one #orders temp table and UPDATE's a persons suggested orders depending on existing orders.
CTE's
CTE's are awesome for readability when dealing with single queries. When creating reports that requires analysis using PIVOT's,Aggregates, etc. with tons of lines of code, CTE's provide readability by being able to separate a huge query into logical sections.
Sometimes there is a combination of both. When more than one query is required. Its still useful to break down some of those queries with CTE's.
I hope this is of some usefulness, cheers!