简体   繁体   中英

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
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM