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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

Reply
Anders_Jensen
Regular Visitor

Generate line chart based on timerange

Hi,

 

Im currently in a situation where I would like to genererate a line chart based on the following data:

 

table.png

 

The output should be shown like this:

graph.png

 

 

The issue is that i have like 200.000 rows, and the only way I can figure out to do is is to create like pr. day in range of each product. But this will be an issue when i talk about subscription that might have a active period on a year or more.

 

Is there any function in Power BI, so im not forced to generate alot of date for such a simple repport?

 

Maybe im to blind an the answer might be in front of me without knowing it.

 

Regards

Anders Jensen

1 REPLY 1
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @Anders_Jensen,

 

In my test, I calculated data paritially, you can see the workaround below as a reference.

 

Create two date tables:

DateTable1=
    CALENDAR ( DATE ( 2016, 1, 1 ), MAX ( LineChart[Expire_date] ) )

DateTable2 =
    CALCULATETABLE ( DateTable1, DAY ( DateTable1[Date] ) = 1 )

 

In the source table, add serveral calculated columns and measures: 

 

Calculated columns: (in your scenario, you should calculate from "Effective for 1 month" to "Effective for 12 month")

Diff =
    DATEDIFF ( LineChart[Effective_date], LineChart[Expire_date], MONTH )

Effective for 1 month =
    IF ( LineChart[Diff] >= 1, 1, 0 )
Effective for 2 month =
    IF ( LineChart[Diff] >= 2, 1, 0 )
Effective for 3 month =
    IF ( LineChart[Diff] >= 3, 1, 0 )

 

Measures: (in your scenario, you should add 12 measures)

Measure 1 =
    CALCULATE ( SUM ( LineChart[Effective for 1 month] ), ALL ( LineChart ) )
Measure 2 =
    CALCULATE ( SUM ( LineChart[Effective for 2 month] ), ALL ( LineChart ) )
Measure 3 =
    CALCULATE ( SUM ( LineChart[Effective for 3 month] ), ALL ( LineChart ) )

 

Create some calculated tables:

Table1 =
    ADDCOLUMNS (
        LineChart,
        "Count1", [Measure 1],
        "Count2", [Measure 2],
        "Count3", [Measure 3]
    )

Table2 =
    UNION (
        ADDCOLUMNS ( SELECTCOLUMNS ( 'Table1', "Count", 'Table1'[Count1] ), "index", 1 ),
        ADDCOLUMNS ( SELECTCOLUMNS ( 'Table1', "Count", 'Table1'[Count2] ), "index", 2 ),
        ADDCOLUMNS ( SELECTCOLUMNS ( 'Table1', "Count", 'Table1'[Count3] ), "index", 3 )
    )

Table3 =
    SUMMARIZE ( 'Table2', 'Table2'[Date2], "Count", AVERAGE ( 'Table2'[Count] ) )

Table4 = CROSSJOIN(DateTable1,Table3)

Table5 =
    CALCULATETABLE (
        Table4,
        FILTER ( Table4, Table4[Date2].[MonthNo] = Table4[Date].[MonthNo] )
    )

 

In the line chart, put Table5[Date] into Axis and Table5[Count] into value.

 

3.PNG

 

Thanks,
Yuliana Gu

 

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Fabric Data Days is here Carousel

Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.