DAX Iterator Behavior - powerbi

I don't think this is doing what I want it to do. I have a fact table with columns date, weekstarting, customer, product and qtyshipped and I want an average product sales including dates with 0 sales. The 0 sales dates don't exist in the table. If I use an iterator does this do what I think its doing? I've grouped by week.
AVERAGEX(VALUES(facttable[weekstarting]),SUM(fact[qtyshipped]))
If this doesn't work this way is there a way to make a measure that would account for these 0s without editing the fact table? I can't seem to find a function that would do this.

It'd just bypass the average function and use a SUM and divide by DATEDIFF set to days, weeks or what ever you want the average of.
DIVIDE(
SUM( fact[qtyshipped] ),
DATEDIFF(
facttable[weekstarting],
facttable[weekending],
WEEK
)
)

Related

Power Bi Calculating number of days dynamically

I am using a slicer to determine a certain periode of time (e.g. 01.10.19 - 31.10.19) and now I want Power Bi to calculate how many days are included (in this case it would be: 31). Of course the calculation needs to be updated every time I use the slicer. Is there any possibility to do so? I have literally no idea...
Create a measure to calculate the difference between the max and min dates in your date table, which is filtered by this slicer. You can use DATEDIFF function for that. In this case the number of days will be calculated as:
Number of days = DATEDIFF(MIN('Calendar'[Date]); MAX('Calendar'[Date]); DAY) + 1

Can a measure be created in Power BI that references two tables that share no relationship?

I'm trying to create a matrix table in Power BI to display the monthly rent projections for a number of properties. I thought I could simply create a measure that summed the rent from one table and then displayed it by month based on start and end date conditions, but it's been a while since I created any measures and I had forgotten that there needs to be a relationship between columns, among other things.
Data Model
A site can have more than one lease associated with it and a lease can have both car-parks and floors associated with it, of which there can be multiple.
In addition to the tables in the linked image, once I had sorted out what I thought would be the easy step I was going to add another table which includes the estimated percentage rent increase and the period in which the increase will occur.
I started out by trying to create a measure along the lines of the following:
Matrix Test =
IF (
HASONEVALUE ( Period[Month] ),
IF (
Period[Month] >= Leases[Custom Start Date],
SUM ( Floor_Rent[Annual Rent] ) / 12,
0
),
0
)
This would need to be expanded upon because the end date of a lease would also need to be taken into consideration.
As well as forgetting about the relationship requirements, I've forgotten how to deal with the issue of narrowing down to a single value within a column.
The result is supposed to be something that looks like this:
The blanks indicate a lease that starts in the future or ends within the time-frame displayed.
When I try linking the Leases table and the Period table on Leases[Start month for current term] and Period[Month] all I can get to is a table that shows the rent amount in the month the lease starts.
Is what I'm trying to achieve possible? If so, how do I accomplish the desired result?
Link to .pbix file
Solution
The direct answer to the title question is probably 'no', but while trying to figure out how I could use Pratik Bhavsar's LOOKUPVALUE suggestion I had a thought and performed a clumsy google search - power bi create table for each value in column - and found this post. By meddling with some of the DAX in said post I was able to come up with the following:
Test Table =
GENERATE(
SELECTCOLUMNS(
VALUES(Leases[Lease ID]),"Lease ID",[Lease ID]
),
SELECTCOLUMNS(
VALUES(Period[Month]),"Month",[Month]
)
)
The result is a table with each Lease ID mapped against each Month. I can't claim to understand exactly how the functions work, and it's not the outcome I thought I needed, but it allows me to achieve exactly what I set out to do.
I've accepted Pratik Bhavsar's answer because it effectively accomplishes the same thing as the work around I implemented. Pratik's solution might be better than what I eventually landed on, but I need to have a closer look at how the two compare.
The following DAX will give you a table with all buildings mapped against all rows in the period table, eliminating the requirement of a relationship.
SiteToPeriod =
CROSSJOIN(
SELECTCOLUMNS(Sites1, "Building name/label", Sites1[Building name/label]),
Period
)

Why is RankX always returning a 1?

I am using the AdventureWorks2016 data warehouse database. I created a measure named 'Total Sales Rank', which can be seen below. I am simply trying to rank each product according to sales (internet sales). The 'Total Sales' column in the table below is a measure (Sum([SalesAmount])) which sums all sales. I cannot figure out why RankX is returning 1 for each product. There are no filters in place. All the tables are properly related.
By the way, there are other questions somewhat like this but different enough where the answers do not help this situation.
You need to use ALL('Product') instead of just 'Product'.
Since you have products as filters (yes, you do!), for each row in your report RANKX "sees" only one record (for the product of the row). That's why you are getting "1"s. Instead, in each record you need to "see" the entire table, so that RANKX can compare multiple rows. This is accomplished by using ALL() function (or ALLSELECTED, etc).
This article might help you further:
Using RANKX

Power BI Matrix - Only Show Subtotals for Numeric Values

Fairly new to Power BI, trying to replicate SSRS reports but am struggling with what in SSRS would be really simple.
I have a matrix which has subtotal rows for the "groups". Some of the values in the matrix are text values rather than numbers. I want to remove the text "subtotals" from the subtotal row, but can only see how to remove the entire row.
For example, I have a value called Deal Type which can hold Growth, Primary or Secondary so in the subtotal row, I am seeing Growth, where I actually don't want to see anything.
We are evaluating Power BI for our business and it seems one day we find something that we love and then next day, a bunch of minus points.
Thanks for your help
EDIT
As you will see, for the subtotal and total rows, I don't want to see Primary, France, and EUR but I do want the values of the numeric columns.
Unrealized and CompanyName are used as the Rows, for security reasons can't show the Company Names.
Hope that helps
It's hard to give a precise answer without any visibility of your actual data structure... But it sounds like you need to create a measure, something like:
=IF (
HASONEVALUE ( MyTable[Group Item] ),
FIRSTNONBLANK ( MyTable[Deal Type], 1 ),
BLANK ()
)

Power BI DateDiff seems to return incorrect number of days

I'm using DAX DateDiff in Power BI to calculate the number of days between two dates, like this:
DaysDiff = DATEDIFF('MyTable'[Sales Order Date],
'MyTable'[Paid Date],DAY)
The formula is however returning some odd looking results, such as:
I would expect to see the actual number of days between the dates. For example, the number of days between 3/31/2017 and 12/4/2017 should be 248.
Both source columns are formatted as dates, and appear in the actual data as shown here.
How should the difference be calculated? I also tried a different formulation, which returns the same result:
DayDiff = 1.* ('MyTable'[Paid Date]-'MyTable'[Sales Order Date])
From the hint of the DaysDiff, my guess is that you have multiple records with same Sales Order Date and Paid Date, and Power BI has aggregated (default Sum) the results of all to one number.
If you change the summarization to either Average/Minimum/Maximum it should work fine.