Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
kent_n
Frequent Visitor

month range combines with time range

Hi 

 

Im an absolute novice and tried google with no luck. 

Completely failed my first try to explain my issue (thanx @daXtreme :), hopefully this might explain what I want to achieve.

 

The following measure is working just fine, but only between april 1st and october 31st. 

From november 1st to march 31st the filtered value 

fixed_prices[Pristabell]="Profit_low" should instead be 
fixed_prices[Pristabell]="Profit_high" for all the hours between 06-22 (06AM-10PM)
Hours between 22-06 (10PM-06AM) are always "Profit_low" year around.

 

Subvention & Grid Compensation = 
(CALCULATE(
    SUMX(FILTER(
        fixed_prices,fixed_prices[Pristabell]="Elsubvention"||fixed_prices[Pristabell]="Profit_low"),fixed_prices[öre/KwH (ink moms)])) / 100)
        * SUM(Energy_sales_price[Production])

 

Energy_sales_price

kent_n_0-1667658716667.png

fixed_prices

kent_n_1-1667658794983.png

hour_table

kent_n_2-1667658913915.png

date_table

kent_n_3-1667659094034.png

 

 

Thanks in advance 🙂

1 ACCEPTED SOLUTION
daXtreme
Solution Sage
Solution Sage

Subvention & Grid Compensation =
// To get what you want you have to
// iterate over Date and Timme and
// take action accordingly.
// The dimensions should be connected
// by 1->>-* to the fact table. fixed_prices
// is a stand-alone table without any connections.
//
// Then you can write something like:
var SwitchMonthNumbers = 
    {
        1,  -- jan
        2,  -- feb
        3,  -- mar
        11, -- nov
        12  -- dec
    }
var Output = 
    sumx(
        summarize(
            Energy_sales_price,
            date_table[Date],
            // Make sure you've got MonthNumbers
            // in date_table.
            date_table[MonthNumber],
            hour_table[Timme],
            hour_table[High_low_hour]
        ),
        var CurrentMonthNumber = date_table[MonthNumber]
        var TotalProduction = 
            calculate( 
                SUM( Energy_sales_price[Production] ) 
            )
        var HighLowProfit = 
            if( hour_table[High_low_hour] = "High",
                "Profit_high",
                "Profit_low"
            )
        var FixedPriceTableFilter =
            {
                "Elsubvention",
                if(
                    CurrentMonthNumber in SwitchMonthNumbers,
                    HighLowProfit,
                    "Profit_low"
                )
            }
        var FixedPrice =
            SUMX(
                FILTER(
                    fixed_prices,
                    fixed_prices[Pristabell] in FixedPriceTableFilter
                ),
                fixed_prices[öre/KwH (ink moms)]
            )
            * TotalProduction / 100
        return
            FixedPrice
    )
return
    Output

Something like this. I did not do any optimization on this. Wrote it without any real data and model. Might work... might not. Try to adjust it to your model.

View solution in original post

4 REPLIES 4
daXtreme
Solution Sage
Solution Sage

Subvention & Grid Compensation =
// To get what you want you have to
// iterate over Date and Timme and
// take action accordingly.
// The dimensions should be connected
// by 1->>-* to the fact table. fixed_prices
// is a stand-alone table without any connections.
//
// Then you can write something like:
var SwitchMonthNumbers = 
    {
        1,  -- jan
        2,  -- feb
        3,  -- mar
        11, -- nov
        12  -- dec
    }
var Output = 
    sumx(
        summarize(
            Energy_sales_price,
            date_table[Date],
            // Make sure you've got MonthNumbers
            // in date_table.
            date_table[MonthNumber],
            hour_table[Timme],
            hour_table[High_low_hour]
        ),
        var CurrentMonthNumber = date_table[MonthNumber]
        var TotalProduction = 
            calculate( 
                SUM( Energy_sales_price[Production] ) 
            )
        var HighLowProfit = 
            if( hour_table[High_low_hour] = "High",
                "Profit_high",
                "Profit_low"
            )
        var FixedPriceTableFilter =
            {
                "Elsubvention",
                if(
                    CurrentMonthNumber in SwitchMonthNumbers,
                    HighLowProfit,
                    "Profit_low"
                )
            }
        var FixedPrice =
            SUMX(
                FILTER(
                    fixed_prices,
                    fixed_prices[Pristabell] in FixedPriceTableFilter
                ),
                fixed_prices[öre/KwH (ink moms)]
            )
            * TotalProduction / 100
        return
            FixedPrice
    )
return
    Output

Something like this. I did not do any optimization on this. Wrote it without any real data and model. Might work... might not. Try to adjust it to your model.

Sorry, eent through the whole year and double checked some vaulues.

I forgot that the conditions only apply to monday-friday! Saturday and sundays are always Low.

 

I´ve added a Column in my date_table named Day of week with monday = 0 and sunday = 6

I can´t figure out how to add this 😞

Worked right away! Thanks alot!


daXtreme
Solution Sage
Solution Sage

Completely unclear. Please get familiar with this first: How to Get Your Question Answered Quickly - Microsoft Power BI Community

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors